5. 使用如下的代碼替換internalCreate中的代碼
protected ISymbol internalCreate(String symbolName, int scope, IAdaptable context, List problems)
{
//得到上下文
final IStructuredDocumentContext sContext =(IStructuredDocumentContext)
context.getAdapter(IstructuredDocumentContext.class);
// 為上下文建立一個DOM上下文
final IDOMContextResolver domResolver =
IStructuredDocumentContextResolverFactory.INSTANCE.getDOMContextResolver(sContext);
if (domResolver != null)
{
final Node curNode = domResolver.getNode();
// node必須是
xml屬性
if (curNode instanceof Attr)
{
final Attr attr = (Attr) curNode;
final Node owningElement = attr.getOwnerElement();
if (owningElement != null)
{
IProject iProject = workspaceResolver.getProject();
if (iProject != null)
{
return handleSymbolCreation(symbolName, sContext, attr, owningElement, iProject);
}
}
}
}
return null;
}
6. 下面讓我們加一個private方法來建立符號(Symbol)。