当前位置: 首页>>代码示例>>Java>>正文


Java ContentAssistUtils.getNodeAt方法代码示例

本文整理汇总了Java中org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils.getNodeAt方法的典型用法代码示例。如果您正苦于以下问题:Java ContentAssistUtils.getNodeAt方法的具体用法?Java ContentAssistUtils.getNodeAt怎么用?Java ContentAssistUtils.getNodeAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils的用法示例。


在下文中一共展示了ContentAssistUtils.getNodeAt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeHoverHelp

import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; //导入方法依赖的package包/类
/**
 * Retrieves documentation to display in the hover help popup.
 * 
 * @return String any documentation information to display <code>null</code>
 *         if there is nothing to display.
 * 
 */
protected String computeHoverHelp(ITextViewer textViewer,
		int documentPosition) {
	String result = null;

	IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer,
			documentPosition);
	if (treeNode == null) {
		return null;
	}
	IJSONNode node = (IJSONNode) treeNode;
	IJSONNode parentNode = node.getParentNode();

	IStructuredDocumentRegion flatNode = ((IStructuredDocument) textViewer
			.getDocument()).getRegionAtCharacterOffset(documentPosition);
	if (flatNode != null) {
		ITextRegion region = flatNode
				.getRegionAtCharacterOffset(documentPosition);
		if (region != null) {
			result = computeRegionHelp(treeNode, parentNode, flatNode,
					region);
		}
	}

	return result;
}
 
开发者ID:angelozerr,项目名称:eclipse-wtp-json,代码行数:33,代码来源:JSONHoverProcessor.java

示例2: detectHyperlinks

import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; //导入方法依赖的package包/类
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
		IRegion region, boolean canShowMultipleHyperlinks) {
	if ((region != null) && (textViewer != null)) {

		IStructuredDocumentRegion documentRegion = ContentAssistUtils
				.getStructuredDocumentRegion(textViewer, region.getOffset());
		WebResourcesTextRegion attrValueRegion = DOMHelper.getTextRegion(
				documentRegion, region.getOffset());
		if (attrValueRegion != null) {
			switch (attrValueRegion.getType()) {
			case CSS_CLASS_NAME:
			case CSS_ID:
				// hyperlink is done for @id or @class
				WebResourceRegion classNameRegion = DOMHelper.getCSSRegion(
						attrValueRegion, documentRegion,
						textViewer.getDocument(), region.getOffset());
				if (classNameRegion != null) {
					// Try to find CSS class name or CSS ID and build
					// Hyperlink
					IDOMNode node = (IDOMNode) ContentAssistUtils
							.getNodeAt(textViewer, region.getOffset());
					CSSHyperlinkTraverser traverser = new CSSHyperlinkTraverser(
							node, classNameRegion);
					IProgressMonitor monitor = null;
					traverser.process(monitor);
					return traverser.getHyperlinks();
				}
			default:
				// Do nothing : WTP already implements hyperlink for
				// script/@src and
				// link/@href
			}
		}
	}
	return null;
}
 
开发者ID:angelozerr,项目名称:eclipse-wtp-webresources,代码行数:38,代码来源:CSSHyperlinkDetector.java

示例3: getAdditionalInfo

import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; //导入方法依赖的package包/类
private String getAdditionalInfo(ITextViewer textViewer,
		WebResourceRegion resourceRegion) {
	IDOMNode xmlnode = (IDOMNode) ContentAssistUtils.getNodeAt(textViewer,
			resourceRegion.getOffset());
	IProgressMonitor monitor = null;
	switch (resourceRegion.getType()) {
	case CSS_CLASS_NAME:
	case CSS_ID:
		return getCSSHoverInfo(resourceRegion, xmlnode, monitor);
	case IMG_SRC:
		return getImageHoverInfo(resourceRegion, xmlnode, monitor);
	default:
		return getFileHoverInfo(resourceRegion, xmlnode, monitor);
	}
}
 
开发者ID:angelozerr,项目名称:eclipse-wtp-webresources,代码行数:16,代码来源:WebResourcesHoverProcessor.java

示例4: computeHoverHelp

import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; //导入方法依赖的package包/类
@Override
protected String computeHoverHelp(ITextViewer textViewer,
		int documentPosition) {
	String result = null;
	IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer,
			documentPosition);
	if (treeNode == null) {
		return null;
	}
	Node node = (Node) treeNode;

	while ((node != null) && (node.getNodeType() == Node.TEXT_NODE)
			&& (node.getParentNode() != null)) {
		node = node.getParentNode();
	}
	IDOMNode parentNode = (IDOMNode) node;

	IStructuredDocumentRegion flatNode = ((IStructuredDocument) textViewer
			.getDocument()).getRegionAtCharacterOffset(documentPosition);
	if (flatNode != null) {
		ITextRegion region = flatNode
				.getRegionAtCharacterOffset(documentPosition);
		if (region != null) {
			result = computeRegionHelp(treeNode, parentNode, flatNode,
					region, documentPosition, textViewer.getDocument());
		}
	}

	return result;
}
 
开发者ID:angelozerr,项目名称:angularjs-eclipse,代码行数:31,代码来源:HTMLAngularTagInfoHoverProcessor.java

示例5: computeCompletionProposals

import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("rawtypes")
public List computeCompletionProposals(CompletionProposalInvocationContext context, IProgressMonitor monitor) {

	ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();

	try {
		IDocument document = context.getDocument();
		int cursorposition = context.getInvocationOffset();
		Node node = (Node)ContentAssistUtils.getNodeAt(context.getViewer(), cursorposition);

		// Get all the known namespaces for this point in the document
		ArrayList<QName> namespaces = getNodeNamespaces(node);

		// Get the text entered before the cursor of this auto-completion invocation
		String pattern = getPattern(document, cursorposition);

		// Collect attribute processors if we're in an HTML element
		if (node instanceof IDOMElement) {
			
			// Make sure there's some whitespace before new attribute suggestions
			if (!pattern.isEmpty() || (pattern.isEmpty() && (cursorposition == 0 ||
					Character.isWhitespace(document.getChar(cursorposition - 1))))) {
				
				List<AttributeProcessor> processors = ProcessorCache.getAttributeProcessors(namespaces, pattern);
				for (AttributeProcessor processor: processors) {
					proposals.add(new AttributeProcessorCompletionProposal(processor,
							pattern.length(), cursorposition));
				}
			}

		}
	}
	catch (BadLocationException ex) {
		ex.printStackTrace();
	}

	return proposals;
}
 
开发者ID:tduchateau,项目名称:thymeleaf-eclipse-plugin,代码行数:43,代码来源:ProcessorCompletionProposalComputer.java

示例6: getHoverInfo

import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("deprecation")
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {

	String hoverinfo = null;

	try {
		int cursorposition = hoverRegion.getOffset();
		Node node = (Node)ContentAssistUtils.getNodeAt(textViewer, cursorposition);

		// Figure out what the cursor is hovering over
		String surroundingtext = getSurroundingWord(textViewer.getDocument(), hoverRegion.getOffset());
		int separatorindex = surroundingtext.indexOf(':');

		// Retrieve processor documentation on attribute or element nodes
		if (node instanceof IDOMElement && separatorindex != -1) {
			String dialectprefix = surroundingtext.substring(0, separatorindex);
			String processorname = surroundingtext.substring(separatorindex + 1);

			Processor processor = ProcessorCache.getProcessor(dialectprefix, processorname);
			if (processor != null && processor.isSetDocumentation()) {
				return processor.getDocumentation().getValue();
			}
		}
	}
	catch (BadLocationException ex) {
		ex.printStackTrace();
	}

	return hoverinfo;
}
 
开发者ID:tduchateau,项目名称:thymeleaf-eclipse-plugin,代码行数:35,代码来源:ProcessorInfoHoverComputer.java

示例7: computeCompletionProposals

import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; //导入方法依赖的package包/类
@Override
public List computeCompletionProposals(
		CompletionProposalInvocationContext context,
		IProgressMonitor monitor) {

	ITextViewer textViewer = context.getViewer();
	int documentPosition = context.getInvocationOffset();

	setErrorMessage(null);

	fTextViewer = textViewer;

	IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer,
			documentPosition);

	IJSONNode node = (IJSONNode) treeNode;
	while ((node != null) && (node.getNodeType() == Node.TEXT_NODE)
			&& (node.getParentNode() != null)) {
		node = node.getParentNode();
	}

	ContentAssistRequest contentAssistRequest = null;

	IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
	ITextRegion completionRegion = getCompletionRegion(documentPosition,
			node);

	String matchString = getMatchString(sdRegion, completionRegion,
			documentPosition);

	// compute normal proposals
	contentAssistRequest = computeCompletionProposals(matchString,
			completionRegion, (IJSONNode) treeNode, node, context);
	if (contentAssistRequest == null) {
		contentAssistRequest = new ContentAssistRequest(
				(IJSONNode) treeNode, node.getParentNode(), sdRegion,
				completionRegion, documentPosition, 0, ""); //$NON-NLS-1$
		setErrorMessage(JSONUIMessages.Content_Assist_not_availab_UI_);
	}

	/*
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=123892 Only set this
	 * error message if nothing else was already set
	 */
	if (contentAssistRequest.getProposals().size() == 0
			&& getErrorMessage() == null) {
		setErrorMessage(JSONUIMessages.Content_Assist_not_availab_UI_);
	}

	ICompletionProposal[] props = contentAssistRequest
			.getCompletionProposals();
	return (props != null) ? Arrays.asList(props) : new ArrayList(0);
}
 
开发者ID:angelozerr,项目名称:eclipse-wtp-json,代码行数:54,代码来源:AbstractJSONCompletionProposalComputer.java

示例8: computeCompletionProposals

import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    fTextViewer=viewer;
    IDocument document=viewer.getDocument();
    int documentPosition = offset;
    String projectSSVersion=CorePreferencesSupport.getInstance().getProjectSpecificPreferencesValue(SilverStripePreferences.SILVERSTRIPE_VERSION, SilverStripeVersion.getDefaultVersion(), this.getProject(document));
    
    IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, documentPosition);

    Node node = (Node) treeNode;
    while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) {
        node = node.getParentNode();
    }
    IDOMNode xmlnode = (IDOMNode) node;
    
    IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
    ITextRegion completionRegion = getCompletionRegion(documentPosition, node);
    
    ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();

    // adjust offset to end of normalized selection
    if (selection.getOffset() == offset)
        offset = selection.getOffset() + selection.getLength();

    String prefix = getMatchString(sdRegion, completionRegion, documentPosition);
    Region region = new Region(offset - prefix.length(), prefix.length());
    TemplateContext context = createContext(viewer, region, offset - prefix.length());
    if (context == null)
        return new ICompletionProposal[0];
    // name of the selection variables {line, word}_selection
    context.setVariable("selection", prefix); //$NON-NLS-1$
    
    // TODO Filter based on the completion region context ie if SS open only show ss_open stuff
    Template[] templates = getTemplates(fContextTypeId);

    List matches = new ArrayList();
    for (int i = 0; i < templates.length; i++) {
        Template template = templates[i];
        try {
            context.getContextType().validate(template.getPattern());
        }
        catch (TemplateException e) {
            continue;
        }
        
        if(template instanceof SilverStripeTemplate) {
            SilverStripeTemplate ssTemplate=(SilverStripeTemplate) template;
            
            if ((template.matches(prefix, fContextTypeId)) && (ssTemplate.ssVersions().length==0 || Arrays.asList(ssTemplate.ssVersions()).contains(projectSSVersion))) {
                matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
            }
        }else if (template.matches(prefix, fContextTypeId)) {
            matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
        }
    }

    Collections.sort(matches, fgProposalComparator);

    return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
}
 
开发者ID:UndefinedOffset,项目名称:eclipse-silverstripedt,代码行数:61,代码来源:SSTemplateCompletionProcessor.java


注:本文中的org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils.getNodeAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。