/*
* $RCSfile: JSParser.java,v $
*
* Copyright 2002
* CH-1700 Fribourg, Switzerland
* All rights reserved.
*
*========================================================================
* Modifications history
*========================================================================
* $Log: JSParser.java,v $
* Revision 1.1 2004/02/26 02:25:42 agfitzp
* renamed packages to match xml & css
*
* Revision 1.1 2004/02/05 03:10:08 agfitzp
* Initial Submission
*
* Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp
* Experimental work for Classes view
*
* Revision 1.6 2003/12/10 20:19:16 agfitzp
* 3.0 port
*
* Revision 1.5 2003/06/21 03:48:51 agfitzp
* fixed global variables as functions bug
* fixed length calculation of instance variables
* Automatic outlining is now a preference
*
* Revision 1.4 2003/05/30 20:53:09 agfitzp
* 0.0.2 : Outlining is now done as the user types. Some other bug fixes.
*
* Revision 1.3 2003/05/28 20:47:58 agfitzp
* Outline the document, not the file.
*
* Revision 1.2 2003/05/28 15:20:00 agfitzp
* Trivial change to test CVS commit
*
* Revision 1.1 2003/05/28 15:17:12 agfitzp
* net.sf.wdte.js.core 0.0.1 code base
*
*========================================================================
*/
package net.sf.wdte.js.core.parser;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import net.sf.wdte.js.core.model.*;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.rules.IToken;
/**
* DOCUMENT ME!
*
* @author Addi
*/
public class JSParser
{
public static final String FUNCTION = "function";
/**
* line separator
*/
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
/**
* Array of system types to ignore.
*/
private static String[] systemClassNames= {"Array","String"};
protected HashMap systemClassMap = new HashMap();
protected IFile sourceFile;
protected IDocument sourceDocument;
protected HashMap functions = new HashMap();
protected HashMap classes = new HashMap();
protected HashMap globalVariables = new HashMap();
protected List elementList = new LinkedList();
protected JSSyntaxScanner scanner = new JSSyntaxScanner();
/**
* Constructor for JSParser.
*/
public JSParser()
{
super();
int i;
for(i = 0;i < systemClassNames.length; i++)
{
String aName = systemClassNames[i];
systemClassMap.put(aName, aName);
}
}
/**
* Returns a string containing the contents of the given file. Returns an empty string if there
* were any errors reading the file.
* @param file
*
* @return
*/
protected static String getText(IFile file)
{
try
{
InputStream in = file.getContents();
return streamToString(in);
} catch (Exception e)
{
e.printStackTrace();
}
return "";
}
protected static String streamToString(InputStream in) throws IOException
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int read = in.read(buf);
while (read > 0)
{
out.write(buf, 0, read);
read = in.read(buf);
}
return out.toString();
}
/**
* Skips ahead and finds next non-whitespace token.
*
*/
public IToken nextNonWhitespaceToken()
{
IToken aToken = scanner.nextToken();
while (!aToken.isEOF() && aToken.isWhitespace())
{
aToken = scanner.nextToken();
}
return aToken;
}
/**
* Parses the input given by the argument.
*
* @param file the element containing the input text
*
* @return an element collection representing the parsed input
*/
public List parse(IFile file)
{
this.sourceFile = file;
return parse(new Document(getText(file)));
}
/**
* Parses the input given by the argument.
*
* @param aSourceDocument the element containing the input text
*
* @return an element collection representing the parsed input
*/
public List parse(IDocument aSourceDocument)
{
sourceDocument = aSourceDocument;
scanner.setRange(sourceDocument, 0, sourceDocument.getLength());
IToken token = scanner.nextToken();
while (!token.isEOF())
{
int offset = scanner.getTokenOffset();
int length = scanner.getTokenLength();
String expression = getExpression(offset, length);
if (token.equals(JSSyntaxScanner.TOKEN_FUNCTION))
{
addFunction(expression, offset, length);
}
if (token.equals(JSSyntaxScanner.TOKEN_DEFAULT))
{
//We need to check if the token is already a function or class
if (functions.containsKey(expression) || classes.containsKey(expression))
{
token = nextNonWhitespaceToken();
if (token.equals(JSSyntaxScanner.TOKEN_MEMBER))
{
detectInstanceMethod(offset, expression);
} else
{
detectClassMethod(token, offset, expression);
}
} else
{
if (expression.equals("var"))
{
detectGlobalVariable();
}
}
}
token = scanner.nextToken();
}
return elementList;
}
private void addFunction(String expression, int offset, int length)
{
String functionSignature = getNaked(expression);
int braceOffset = functionSignature.indexOf("(");
String functionName = functionSignature.substring(0, braceOffset).trim();
String arguments =
functionSignature.substring(functionSignature.indexOf("("), functionSignature.indexOf(")") + 1);
if (functionName.indexOf(".") >= 0)
{
//If the function signature includes .prototype. then it's a member.
if (functionName.indexOf(".prototype.") >= 0)
{
String className = functionName.substring(0, functionName.indexOf("."));
String memberName = functionName.substring(functionName.lastIndexOf(".") + 1);
JSInstanceMethodElement aMethod =
this.addInstanceMethod(memberName, className, arguments, offset, offset, length);
detectInstanceMethodContext(className, aMethod);
} else
{
String className = functionName.substring(0, functionName.indexOf("."));
if (functions.containsKey(className) || classes.containsKey(className))
{
String memberName = functionName.substring(functionName.lastIndexOf(".") + 1);
JSFunctionElement aMethod =
this.addClassMethod(memberName, className, arguments, offset, offset, length);
}
}
} else
{
if(! functions.containsKey(functionName))
{
JSFunctionElement aFunction = new JSFunctionElement(this.sourceFile, functionName, arguments, offset, length);
elementList.add(aFunction);
functions.put(functionName, aFunction);
detectFunctionContext(aFunction);
}
}
}
/**
*
*/
private void checkForSpecialGlobalTypes(JSGlobalVariableElement aVariable)
{
IToken token = nextNonWhitespaceToken();
if (!token.isEOF())
{
if(!checkForDynamicClass(aVariable, token))
{
checkForAnonymousFunction(aVariable, token);
}
}
}
/**
*
*/
private boolean checkForDynamicClass(JSGlobalVariableElement aVariable, IToken rhsToken)
{
if (rhsToken.equals(JSSyntaxScanner.TOKEN_DEFAULT))
{
int offset = scanner.getTokenOffset();
int length = scanner.getTokenLength();
String expression = getExpression(offset, length);
if (expression.equals("new"))
{
IToken token = nextNonWhitespaceToken();
if (!token.isEOF())
{
if (token.equals(JSSyntaxScanner.TOKEN_DEFAULT))
{
offset = scanner.getTokenOffset();
length = scanner.getTokenLength();
expression = getExpression(offset, length);
if(! isSystemC
没有合适的资源?快使用搜索试试~ 我知道了~
eclipse的js插件下载
共67个文件
java:38个
gif:10个
xml:4个
5星 · 超过95%的资源 需积分: 9 475 下载量 14 浏览量
2009-12-25
10:26:06
上传
评论
收藏 187KB ZIP 举报
温馨提示
eclipse的js插件。 eclipse对java的支持很好,对js一直没有很好的提示。 那么试试这个插件吧。 使用方法: 1.解压文件,将plugins文件夹下的内容拷贝到eclipse目录的plugins文件夹内。 2.重新启动eclipse。 3.安装完成。 选定需要编辑的js->右键->open with -> JSEclipse 即可打开js编辑器
资源推荐
资源详情
资源评论
收起资源包目录
net.sf.wdte.js_0.0.9.zip (67个子文件)
plugins
net.sf.wdte.js.core_0.0.9
net.sf.wdte.js.core.jar 27KB
.project 680B
plugin.properties 525B
net.sf.wdte.js.coresrc.zip 25KB
src
net
sf
wdte
js
core
parser
JSPartitionScanner.java 3KB
JSWhitespaceDetector.java 1KB
JSScanner.java 2KB
JSWordDetector.java 2KB
JSSyntaxScanner.java 3KB
JSSyntaxModelFactory.java 4KB
NonRuleBasedDamagerRepairer.java 5KB
JSReferenceDetector.java 1022B
JSParser.java 24KB
PredicateWordRule.java 3KB
JSStringScanner.java 2KB
model
JSFunctionElement.java 2KB
JSElementList.java 4KB
JSClassVariableElement.java 1KB
JSElement.java 4KB
JSInstanceMethodElement.java 1KB
JSInstanceVariableElement.java 1KB
JSGlobalVariableElement.java 1KB
JSClassElement.java 2KB
JSElementCategories.java 1KB
JSClassMethodElement.java 1KB
JSCorePlugin.java 3KB
.classpath 307B
plugin.xml 715B
build.properties 492B
net.sf.wdte.core_0.0.1
plugin.xml 485B
webcoresrc.zip 4KB
webcore.jar 3KB
net.sf.wdte.ui_0.0.1
uisrc.zip 43KB
plugin.xml 2KB
net.sf.wdte.js.ui_0.0.9
icons
js.gif 898B
class_variable.gif 131B
instance_method.gif 878B
global_variable.gif 119B
dyn_class_obj.gif 930B
class_obj.gif 160B
instance_variable.gif 138B
func.gif 863B
class_method.gif 879B
sample.gif 983B
.project 757B
net.sf.wdte.js.uisrc.zip 20KB
plugin.properties 636B
src
net
sf
wdte
js
ui
preferences
JavaScriptPreferencePage.java 3KB
PreferenceNames.java 1KB
views
JSClassesView.java 5KB
JSClassesViewContentProvider.java 3KB
JSUIPlugin.java 4KB
model
JSModelAdapterFactory.java 2KB
JSWorkbenchAdapter.java 3KB
JSElementCategories.java 1KB
JSNameSorter.java 2KB
internal
outline
JSOutlinePage.java 3KB
editors
JSEditor.java 4KB
JSImages.java 4KB
JSConfiguration.java 6KB
JSDocumentProvider.java 2KB
JSDoubleClickStrategy.java 4KB
JSColorManager.java 2KB
net.sf.wdte.js.ui.jar 24KB
.classpath 307B
plugin.xml 2KB
build.properties 500B
共 67 条
- 1
mush_me
- 粉丝: 25
- 资源: 51
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页