Java 类org.eclipse.jface.text.hyperlink.IHyperlink 实例源码

项目:pgcodekeeper    文件:SQLEditorHyperLinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
        boolean canShowMultipleHyperlinks) {
    SQLEditor editor = getAdapter(SQLEditor.class);
    PgDbParser parser = editor.getParser();

    int offset = region.getOffset();
    List<PgObjLocation> refs = parser.getObjsForEditor(editor.getEditorInput());
    for (PgObjLocation obj : refs) {
        if (offset > obj.getOffset()
                && offset < (obj.getOffset() + obj.getObjLength())) {
            IHyperlink[] links =  parser.getDefinitionsForObj(obj)
                    .map(def -> new SQLEditorHyperLink(
                            new Region(def.getOffset(), def.getObjLength()),
                            new Region(obj.getOffset(), obj.getObjLength()),
                            obj.getObjName(), def.getFilePath(), def.getLineNumber()))
                    .toArray(IHyperlink[]::new);
            if (links.length != 0) {
                return links;
            }
        }
    }
    return null;
}
项目:vertigo-chroma-kspplugin    文件:KspNameHyperLinkDetector.java   
private IHyperlink[] detectKspName(String currentWord, IRegion targetRegion, FileRegion fileRegion) {

        /* Cherche la déclaration. */
        KspDeclaration kspDeclaration = KspManager.getInstance().findKspDeclarationByConstantCaseName(currentWord);
        if (kspDeclaration == null) {
            return null; // NOSONAR
        }

        /* Vérifie que le focus n'est pas déjà sur la déclaration. */
        if (fileRegion.equals(kspDeclaration.getFileRegion())) {
            return null; // NOSONAR
        }

        /* Renvoie un lien vers la déclaration. */
        return new IHyperlink[] { new KspDeclarationHyperLink(targetRegion, kspDeclaration) };
    }
项目:egradle    文件:GradleHyperlinkDetector.java   
private IHyperlink[] handleFileLink(IRegion lineInfo, GradleHyperLinkResult result) {
    try {
        File folder = editorFile.getParentFile();
        String fileName = result.linkContent;

        File target = new File(folder, fileName); 
        if (!target.exists()) {
            target = new File(fileName);
        }
        if (!target.exists()) {
            return null;
        }

        IFileStore fileStore = EFS.getLocalFileSystem().getStore(target.toURI());
        if (fileStore==null){
            return null;
        }
        IRegion urlRegion = new Region(lineInfo.getOffset() + result.linkOffsetInLine, result.linkLength);
        GradleFileHyperlink gradleFileHyperlink = new GradleFileHyperlink(urlRegion, fileStore);
        return new IHyperlink[] { gradleFileHyperlink };
    } catch (RuntimeException e) {
        return null;
    }
}
项目:bts    文件:XtextSourceViewerConfiguration.java   
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
    List<IHyperlinkDetector> detectors = new LinkedList<IHyperlinkDetector>();
    IHyperlinkDetector[] inheritedDetectors = super.getHyperlinkDetectors(sourceViewer);
    if (inheritedDetectors != null) {
        for (final IHyperlinkDetector detector : inheritedDetectors) {
            detectors.add(new IHyperlinkDetector() {
                public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
                        boolean canShowMultipleHyperlinks) {
                    try {
                        return detector.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
                    }
                    catch (Throwable e) {
                        // fail safe hyperlink detector - prevent others
                        // from failing
                    }
                    return null;
                }

            });
        }
    }
    detectors.add(detector);
    return detectors.toArray(new IHyperlinkDetector[detectors.size()]);
}
项目:bts    文件:OpenDeclarationHandler.java   
public Object execute(ExecutionEvent event) throws ExecutionException {
    XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
    if (xtextEditor != null) {
        ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection();

        IRegion region = new Region(selection.getOffset(), selection.getLength());

        ISourceViewer internalSourceViewer = xtextEditor.getInternalSourceViewer();

        IHyperlink[] hyperlinks = getDetector().detectHyperlinks(internalSourceViewer, region, false);
        if (hyperlinks != null && hyperlinks.length > 0) {
            IHyperlink hyperlink = hyperlinks[0];
            hyperlink.open();
        }
    }       
    return null;
}
项目:Gauge-Eclipse    文件:SpecHyperlinkHelper.java   
@Override
public IHyperlink[] createHyperlinksByOffset(XtextResource resource,
        int offset, boolean createMultipleHyperlinks) {

    EObject eObject = helper.resolveElementAt(resource, offset);
    if (eObject instanceof StepDefinition || 
            eObject instanceof StaticParam || 
            eObject instanceof DynamicParam) {
        IParseResult parseResult = resource.getParseResult();
        INode node = NodeModelUtils.findLeafNodeAtOffset(
                parseResult.getRootNode(), offset);
        while (!(node instanceof CompositeNode && node.getSemanticElement() instanceof StepDefinition)) {
            node = node.getParent();
        }
        String description = StepUtil.getStepText(node);
        if (!openConceptDefinition(eObject, description)) {
            openStepDefinition(description);
        }
    }
    return null;
}
项目:KaiZen-OpenAPI-Editor    文件:LinkOperationHyperlinkDetector.java   
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    Model model = doc.getModel();
    AbstractNode node = model.find(pointer);
    List<AbstractNode> nodes = model.findByType(JsonPointer.compile("/definitions/operation"));
    Iterator<AbstractNode> it = nodes.iterator();

    AbstractNode found = null;
    while (it.hasNext() && found == null) {
        AbstractNode current = it.next();
        AbstractNode value = current.get("operationId");

        if (value != null && Objects.equals(node.asValue().getValue(), value.asValue().getValue())) {
            found = value;
        }
    }

    if (found != null) {
        IRegion target = doc.getRegion(found.getPointer());
        if (target != null) {
            return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
        }
    }

    return null;
}
项目:KaiZen-OpenAPI-Editor    文件:SecuritySchemeHyperlinkDetector.java   
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    Matcher matcher = PATTERN.matcher(pointer.toString());
    String link = matcher.find() ? matcher.group(1) : null;

    if (link != null) {
        Model model = doc.getModel();
        AbstractNode securityScheme = model.find("/components/securitySchemes/" + link);

        if (securityScheme != null) {
            IRegion target = doc.getRegion(securityScheme.getPointer());
            if (target != null) {
                return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
            }
        }
    }
    return null;
}
项目:KaiZen-OpenAPI-Editor    文件:DefinitionHyperlinkDetector.java   
@Override
protected IHyperlink[] doDetect(JsonDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {
    JsonPointer targetPath;
    if (pointer.toString().matches(REQUIRED_PATTERN)) {
        targetPath = getRequiredPropertyPath(doc, info, pointer);
    } else {
        targetPath = getTagDefinitionPath(doc, info, pointer);
    }

    if (targetPath == null) {
        return null;
    }


    IRegion target = doc.getRegion(targetPath);
    if (target == null) {
        return null;
    }

    return new IHyperlink[] { new SwaggerHyperlink(info.text, viewer, info.region, target) };
}
项目:KaiZen-OpenAPI-Editor    文件:AbstractJsonHyperlinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    JsonDocument document = (JsonDocument) textViewer.getDocument();
    JsonPointer basePath = document.getPath(region);

    if (!canDetect(basePath)) {
        return null;
    }

    HyperlinkInfo info = getHyperlinkInfo(textViewer, region);
    if (info == null) {
        return null;
    }

    return doDetect(document, textViewer, info, basePath);
}
项目:APICloud-Studio    文件:JSHyperlinkDetector.java   
/**
 * detectHyperlinks
 * 
 * @param editor
 * @param region
 * @param canShowMultipleHyperlinks
 * @return
 */
public IHyperlink[] detectHyperlinks(AbstractThemeableEditor editor, IRegion region,
        boolean canShowMultipleHyperlinks)
{
    IHyperlink[] result = null;

    if (editor != null && region != null)
    {
        // grab AST
        IParseNode ast = editor.getAST();

        if (ast instanceof JSParseRootNode)
        {
            // gather links
            result = processAST(editor, (JSParseRootNode) ast, region.getOffset());
        }
    }

    if (!canShowMultipleHyperlinks && !ArrayUtil.isEmpty(result))
    {
        result = new IHyperlink[] { result[0] };
    }

    return result;
}
项目:APICloud-Studio    文件:OpenDeclarationAction.java   
/**
 * Open the declaration if possible.
 */
@Override
public void run()
{
    ITextEditor textEditor = getTextEditor();

    if (textEditor instanceof JSSourceEditor)
    {
        ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection();
        IRegion region = new Region(selection.getOffset(), 1);
        JSHyperlinkDetector detector = new JSHyperlinkDetector();
        IHyperlink[] hyperlinks = detector.detectHyperlinks((AbstractThemeableEditor) textEditor, region, true);

        if (!ArrayUtil.isEmpty(hyperlinks))
        {
            // give first link highest precedence
            hyperlinks[0].open();
        }
    }
}
项目:strutsclipse    文件:StrutsXmlHyperlinkDetector.java   
private IHyperlink createClassMethodLink(final IDocument document,
        final String elementValue, final IRegion elementRegion,
        final String className) {
    IHyperlink link = null;

    IType clazz = ProjectUtil.findClass(document, className);
    if (clazz != null) {
        IMethod method = ProjectUtil.findClassParameterlessMethod(clazz,
                elementValue);
        if (method != null) {
            link = new JavaElementHyperlink(elementRegion, method);
        }
    }

    return link;
}
项目:strutsclipse    文件:StrutsXmlHyperlinkDetector.java   
private List<IHyperlink> createPackageExtendsResourcesLink(
        final IDocument document, final String elementValue,
        final IRegion elementRegion) {
    List<IHyperlink> links = new ArrayList<IHyperlink>();

    IPath currentPath = ProjectUtil.getCurrentDocumentPath(document);

    List<ResourceDocument> resources = ProjectUtil
            .findStrutsResources(document);
    for (ResourceDocument rd : resources) {
        if (!rd.getResource().getFullPath().equals(currentPath)) {
            IRegion nameRegion = strutsXmlParser.getPackageNameRegion(
                    rd.getDocument(), elementValue);
            if (nameRegion != null) {
                if (rd.getResource().getType() == IResource.FILE
                        && rd.getResource().exists()) {
                    links.add(new FileHyperlink(elementRegion, (IFile) rd
                            .getResource(), nameRegion));
                }
            }
        }
    }

    return links;
}
项目:strutsclipse    文件:StrutsXmlHyperlinkDetector.java   
private List<IHyperlink> createPackageExtendsJarLinks(
        final IDocument document, final String elementValue,
        final IRegion elementRegion) {
    List<IHyperlink> links = new ArrayList<IHyperlink>();

    List<JarEntryStorage> jarStorages = ProjectUtil
            .findJarEntryStrutsResources(document);
    for (JarEntryStorage jarStorage : jarStorages) {
        IRegion nameRegion = strutsXmlParser.getPackageNameRegion(
                jarStorage.toDocument(), elementValue);
        if (nameRegion != null) {
            links.add(new StorageHyperlink(elementRegion, jarStorage,
                    nameRegion));
        }
    }

    return links;
}
项目:strutsclipse    文件:AbstractStrutsHyperlinkDetector.java   
protected IHyperlink[] linksListToArray(List<IHyperlink> linksList) {
    IHyperlink[] links = null;
    if (linksList != null && !linksList.isEmpty()) {
        // remove null-s
        Iterator<IHyperlink> itr = linksList.iterator();
        while (itr.hasNext()) {
            if (itr.next() == null) {
                itr.remove();
            }
        }

        if (!linksList.isEmpty()) {
            links = linksList.toArray(new IHyperlink[linksList.size()]);
        }
    }
    return links;
}
项目:strutsclipse    文件:TilesXmlHyperlinkDetector.java   
private List<IHyperlink> createDefinitionLocationLinks(
        final IDocument document, final String elementValue,
        final IRegion elementRegion) {
    final List<IHyperlink> links = new ArrayList<IHyperlink>();

    IRegion region = tilesXmlParser.getDefinitionRegion(document,
            elementValue);
    if (region != null) {
        IFile file = ProjectUtil.getCurrentDocumentFile(document);
        if (file.exists()) {
            links.add(new FileHyperlink(elementRegion, file, region));
        }
    }

    return links;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaElementHyperlinkDeclaredTypeDetector.java   
@Override
protected void addHyperlinks(List<IHyperlink> hyperlinksCollector, IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
    try {
        if (element.getElementType() == IJavaElement.FIELD || element.getElementType() == IJavaElement.LOCAL_VARIABLE) {
            String typeSignature= getTypeSignature(element);
            if (!JavaModelUtil.isPrimitive(typeSignature) && SelectionConverter.canOperateOn(editor)) {
                if (Signature.getTypeSignatureKind(typeSignature) == Signature.INTERSECTION_TYPE_SIGNATURE) {
                    String[] bounds= Signature.getIntersectionTypeBounds(typeSignature);
                    qualify|= bounds.length >= 2;
                    for (int i= 0; i < bounds.length; i++) {
                        hyperlinksCollector.add(new JavaElementDeclaredTypeHyperlink(wordRegion, openAction, element, bounds[i], qualify));
                    }
                } else {
                    hyperlinksCollector.add(new JavaElementDeclaredTypeHyperlink(wordRegion, openAction, element, qualify));
                }
            }
        }
    } catch (JavaModelException e) {
        JavaPlugin.log(e);
    }
}
项目:mybatipse    文件:JavaHyperlinkDetector.java   
private IHyperlink linkToXmlElement(IJavaProject project, String targetElement,
    String namespace, String id, IRegion linkRegion, ITextViewer viewer)
{
    IFile mapperXmlFile = MapperNamespaceCache.getInstance().get(project, namespace, null);
    if (mapperXmlFile == null)
        return null;
    IDOMDocument domDoc = MybatipseXmlUtil.getMapperDocument(mapperXmlFile);
    if (domDoc == null)
        return null;
    try
    {
        IDOMNode node = (IDOMNode)XpathUtil.xpathNode(domDoc,
            "//" + targetElement + "[@id='" + id + "']");
        if (node != null)
        {
            IRegion destRegion = new Region(node.getStartOffset(),
                node.getEndOffset() - node.getStartOffset());
            return new ToXmlHyperlink(mapperXmlFile, linkRegion, "Open declaration", destRegion);
        }
    }
    catch (XPathExpressionException e)
    {
        Activator.log(Status.ERROR, e.getMessage(), e);
    }
    return null;
}
项目:mybatipse    文件:XmlHyperlinkDetector.java   
private IHyperlink linkToJavaType(IDocument document, String typeName, Region linkRegion)
    throws JavaModelException
{
    IJavaProject project = MybatipseXmlUtil.getJavaProject(document);
    IType javaType = project.findType(typeName);
    if (javaType == null)
    {
        String found = TypeAliasCache.getInstance().resolveAlias(project, typeName, null);
        if (found != null)
        {
            javaType = project.findType(found);
        }
    }
    if (javaType != null)
    {
        return new ToJavaHyperlink(javaType, linkRegion, javaLinkLabel("class"));
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaElementHyperlinkDeclaredTypeDetector.java   
@Override
protected void addHyperlinks(List<IHyperlink> hyperlinksCollector, IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
    try {
        if (element.getElementType() == IJavaElement.FIELD || element.getElementType() == IJavaElement.LOCAL_VARIABLE) {
            String typeSignature= getTypeSignature(element);
            if (!JavaModelUtil.isPrimitive(typeSignature) && SelectionConverter.canOperateOn(editor)) {
                if (Signature.getTypeSignatureKind(typeSignature) == Signature.INTERSECTION_TYPE_SIGNATURE) {
                    String[] bounds= Signature.getIntersectionTypeBounds(typeSignature);
                    qualify|= bounds.length >= 2;
                    for (int i= 0; i < bounds.length; i++) {
                        hyperlinksCollector.add(new JavaElementDeclaredTypeHyperlink(wordRegion, openAction, element, bounds[i], qualify));
                    }
                } else {
                    hyperlinksCollector.add(new JavaElementDeclaredTypeHyperlink(wordRegion, openAction, element, qualify));
                }
            }
        }
    } catch (JavaModelException e) {
        JavaPlugin.log(e);
    }
}
项目:goclipse    文件:LangHyperlinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion requestedRegion,
        boolean canShowMultipleHyperlinks) {
    if (requestedRegion == null)
        return null;

    ITextEditor textEditor = getAdapter(ITextEditor.class);
    if(textEditor == null) {
        return null;
    }

    IDocument document = textViewer.getDocument();

    IRegion wordRegion = JavaWordFinder.findWord(document, requestedRegion.getOffset());

    return array(createHyperlink(requestedRegion, textEditor, wordRegion));
}
项目:StringEditEclipse    文件:MultiLineHyperlinkDector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
        IRegion region, boolean canShowMultipleHyperlinks) {

    ITextEditor editor = (ITextEditor) getAdapter(ITextEditor.class);
    if (!editor.getTitle().endsWith(".java")) {
        return null;
    }
    IDocumentProvider dp = editor.getDocumentProvider();
    StringUtils textUtils = new StringUtils();
    textUtils.setDoc(dp.getDocument(editor.getEditorInput()).get());
    textUtils.setCursorPosition(StringHandler.getCursorPosition());
    boolean val = textUtils.proccess();
    int cursorPosition = textUtils.getCursorPosition();
    if (cursorPosition < 0) {
        return null;
    }
    if (!val) {
        return null;
    }

    return new IHyperlink[] { new MultiLineHyperlink(new Region(
            textUtils.getStart(), textUtils.getLength())) };
}
项目:n4js    文件:HyperlinkXpectMethod.java   
private String getTargetDescription(XtextResource resource, IHyperlink hyperlink) {
    final StringBuffer sb = new StringBuffer();
    // append hyperlink text. Only consider the element name and ignore the qualified part.
    String hyperlinkText = hyperlink.getHyperlinkText();
    hyperlinkText = hyperlinkText.substring(hyperlinkText.lastIndexOf('.') + 1);
    if (hyperlinkText != null)
        sb.append(hyperlinkText);
    else
        sb.append("<no hyperlink text>");
    // append description of target element (path from the element to the root of the AST)
    final EObject target = getTarget(resource, hyperlink);
    if (target != null) {
        // build chain of ancestor AST elements
        sb.append(": ");
        final int startLen = sb.length();
        EObject currTarget = target;
        while (currTarget != null) {
            if (currTarget instanceof NamedElement || currTarget instanceof IdentifiableElement) {
                if (sb.length() > startLen)
                    sb.append(" in ");
                String name = currTarget instanceof NamedElement ? ((NamedElement) currTarget).getName()
                        : ((IdentifiableElement) currTarget).getName();
                if (name == null || name.trim().length() == 0)
                    name = "<unnamed>";
                else
                    name = "\"" + name + "\"";
                sb.append(name + "(" + currTarget.eClass().getName() + ")");
            }
            currTarget = currTarget.eContainer();
        }
        // add URI of resource
        final URI targetResURI = target.eResource() != null ? target.eResource().getURI() : null;
        final String fname = targetResURI != null ? targetResURI.lastSegment() : null;
        if (fname != null && fname.trim().length() > 0) {
            sb.append(" in file ");
            sb.append(fname);
        }
    }
    return sb.toString();
}
项目:n4js    文件:HyperlinkXpectMethod.java   
private EObject getTarget(XtextResource resource, IHyperlink hyperlink) {
    final ResourceSet resourceSet = resource != null ? resource.getResourceSet() : null;
    final URI uri = hyperlink instanceof XtextHyperlink ? ((XtextHyperlink) hyperlink).getURI() : null;
    final EObject target = resourceSet != null && uri != null ? resourceSet.getEObject(uri, true) : null;
    if (target instanceof SyntaxRelatedTElement)
        return ((SyntaxRelatedTElement) target).getAstElement();
    return target;
}
项目:n4js    文件:N4JSHyperlinkDetector.java   
/**
 * Method copied from super class with only a minor change: call to "readOnly" changed to "tryReadOnly".
 */
@Override
public IHyperlink[] detectHyperlinks(final ITextViewer textViewer, final IRegion region,
        final boolean canShowMultipleHyperlinks) {
    final IDocument xtextDocument = textViewer.getDocument();
    if (!(xtextDocument instanceof N4JSDocument)) {
        return super.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
    }
    final IHyperlinkHelper helper = getHelper();
    return ((N4JSDocument) xtextDocument).tryReadOnly(new IUnitOfWork<IHyperlink[], XtextResource>() {
        @Override
        public IHyperlink[] exec(XtextResource resource) throws Exception {
            if (resource == null) {
                return null;
            }
            if (helper instanceof ISourceViewerAware && textViewer instanceof ISourceViewer) {
                ((ISourceViewerAware) helper).setSourceViewer((ISourceViewer) textViewer);
            }
            return helper.createHyperlinksByOffset(resource, region.getOffset(), canShowMultipleHyperlinks);
        }
    }, null);
}
项目:vertigo-chroma-kspplugin    文件:SqlTableHyperLinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    IDocument document = textViewer.getDocument();

    /* Vérifie qu'on est dans une String de KSP */
    boolean isSqlString = DocumentUtils.isContentType(document, region.getOffset(), KspRegionType.STRING);
    if (!isSqlString) {
        return null; // NOSONAR
    }

    /* Extrait le mot courant. */
    ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
    ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.SNAKE_CASE);
    if (currentWordSelection == null) {
        return null; // NOSONAR
    }
    String currentWord = currentWordSelection.getText();
    if (currentWord == null) {
        return null; // NOSONAR
    }

    /* Extrait un nom de DTO : Calcul le nom en PascalCase */
    String javaName = StringUtils.toPascalCase(currentWord);

    /* Cherche le fichier Java du DTO. */
    DtoFile dtoFile = DtoManager.getInstance().findDtoFile(javaName);

    /* Fichier Java trouvé : on ajoute un lien vers le fichier Java. */
    if (dtoFile != null) {
        IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
        return new IHyperlink[] { new JavaImplementationHyperLink(targetRegion, dtoFile) };
    }

    return null; // NOSONAR
}
项目:vertigo-chroma-kspplugin    文件:FilePathHyperLinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {

    IDocument document = textViewer.getDocument();

    /* Extrait le mot courant. */
    ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
    ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.NOT_SPACE);
    if (currentWordSelection == null) {
        return null; // NOSONAR
    }
    String currentWord = currentWordSelection.getText();
    if (currentWord == null) {
        return null; // NOSONAR
    }

    /* Vérifie que c'est un chemin relatif valide. */
    String absolutePath = getAbsolutePath(currentWord);
    if (absolutePath == null) {
        return null; // NOSONAR
    }

    /* Vérifie que le fichier existe. */
    IFile file = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(absolutePath);
    if (file == null) {
        return null; // NOSONAR
    }

    /* Renvoin un lien vers le fichier dont on a trouvé le chemin. */
    IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
    return new IHyperlink[] { new FileHyperLink(targetRegion, file) };
}
项目:vertigo-chroma-kspplugin    文件:KspNameHyperLinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    IDocument document = textViewer.getDocument();

    /* Extrait le mot courant. */
    ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
    ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.CONSTANT_CASE);
    if (currentWordSelection == null) {
        return null; // NOSONAR
    }
    String currentWord = currentWordSelection.getText();
    if (currentWord == null) {
        return null; // NOSONAR
    }

    IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
    FileRegion fileRegion = new FileRegion(UiUtils.getCurrentEditorFile(), targetRegion.getOffset(), targetRegion.getLength());

    /* Cherche un nom de DTO. */
    IHyperlink[] hyperlinks = detectDtDefinitionName(currentWord, targetRegion, fileRegion);
    if (hyperlinks != null) {
        return hyperlinks;
    }

    /* Cherche un nom de Task. */
    hyperlinks = detectTaskName(currentWord, targetRegion);
    if (hyperlinks != null) {
        return hyperlinks;
    }

    /* Cherche une déclaration KSP autre. */
    return detectKspName(currentWord, targetRegion, fileRegion);
}
项目:vertigo-chroma-kspplugin    文件:KspNameHyperLinkDetector.java   
private IHyperlink[] detectDtDefinitionName(String currentWord, IRegion targetRegion, FileRegion fileRegion) {
    List<IHyperlink> hyperLinks = new ArrayList<>();

    /* Extrait le nom du DTO. */
    String dtName = KspStringUtils.getDtDefinitionName(currentWord);
    if (dtName == null) {
        return null; // NOSONAR
    }

    /* Calcul le nom Java */
    LegacyStrategy strategy = LegacyManager.getInstance().getCurrentStrategy();
    String kspKeyword = strategy.getKspKeyword(KspNature.DT_DEFINITION);
    String javaName = strategy.getKspDeclarationJavaName(dtName, kspKeyword);

    /* Cherche la déclaration KSP de DtDefinition */
    KspDeclaration kspDeclaration = KspManager.getInstance().findKspDeclaration(javaName, KspNature.DT_DEFINITION);

    /* Déclaration KSP trouvé : on ajoute un lien si on n'est pas déjà sur la déclaration. */
    if (kspDeclaration != null && !fileRegion.equals(kspDeclaration.getFileRegion())) {
        hyperLinks.add(new KspDeclarationHyperLink(targetRegion, kspDeclaration));
    }

    /* Cherche le fichier Java du DTO. */
    DtoFile dtoFile = DtoManager.getInstance().findDtoFile(javaName);

    /* Fichier Java trouvé : on ajoute un lien vers le fichier Java. */
    if (dtoFile != null) {
        hyperLinks.add(new JavaImplementationHyperLink(targetRegion, dtoFile));
    }

    if (hyperLinks.isEmpty()) {
        return null; // NOSONAR
    }

    /* On retourne les liens du DTO. */
    return hyperLinks.toArray(new IHyperlink[0]);
}
项目:vertigo-chroma-kspplugin    文件:KspNameHyperLinkDetector.java   
private IHyperlink[] detectTaskName(String currentWord, IRegion targetRegion) {

        List<IHyperlink> hyperLinks = new ArrayList<>();

        /* Extrait un nom de tâche DAO / PAO. */
        String taskName = KspStringUtils.getTaskName(currentWord);
        if (taskName == null) {
            return null; // NOSONAR
        }
        /* Calcul le nom en PascalCase */
        String javaName = StringUtils.toCamelCase(taskName);

        /* Cherche la tâche. */
        DaoImplementation daoImplementation = DaoManager.getInstance().findDaoImplementation(javaName);
        if (daoImplementation == null) {
            return null; // NOSONAR
        }

        /* On ajoute le lien vers la tâche. */
        hyperLinks.add(new JavaImplementationHyperLink(targetRegion, daoImplementation));

        /* Recherche du test unitaire de la Task. */
        JavaClassFile testClass = JavaClassManager.getInstance().findJavaClassTest(daoImplementation);
        if (testClass != null) {
            hyperLinks.add(new JavaTestClassHyperLink(targetRegion, testClass));
        }

        if (hyperLinks.isEmpty()) {
            return null; // NOSONAR
        }

        /* On retourne les liens de la Task. */
        return hyperLinks.toArray(new IHyperlink[0]);
    }
项目:vertigo-chroma-kspplugin    文件:DtoDefinitionPathHyperLinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    IDocument document = textViewer.getDocument();

    /* Extrait le mot courant. */
    ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
    ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.CANONICAL_JAVA_NAME);
    if (currentWordSelection == null) {
        return null; // NOSONAR
    }
    String currentWord = currentWordSelection.getText();
    if (currentWord == null) {
        return null; // NOSONAR
    }

    /* Vérifie qu'on est dans une région entière KspString */
    if (!DocumentUtils.isExactKspString(document, currentWordSelection)) {
        return null; // NOSONAR
    }

    /* Extrait un chemin de définition de DTO. */
    DtoDefinitionPath definitionPath = KspStringUtils.getKasper3DefinitionPath(currentWord);
    if (definitionPath == null) {
        return null; // NOSONAR
    }

    /* Cherche le fichier Java du DTO. */
    DtoFile dtoFile = DtoManager.getInstance().findDtoFile(definitionPath);
    if (dtoFile == null) {
        return null; // NOSONAR
    }

    /* Fichier Java trouvé : on ajoute un lien vers le fichier Java. */
    IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
    return new IHyperlink[] { new JavaImplementationHyperLink(targetRegion, dtoFile) };
}
项目:vertigo-chroma-kspplugin    文件:CanonicalJavaNameHyperLinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    IDocument document = textViewer.getDocument();

    /* Extrait le mot courant. */
    ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
    ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.CANONICAL_JAVA_NAME);
    if (currentWordSelection == null) {
        return null; // NOSONAR
    }
    String currentWord = currentWordSelection.getText();
    if (currentWord == null) {
        return null; // NOSONAR
    }

    /* Vérifie qu'on est dans une région entière KspString */
    if (!DocumentUtils.isExactKspString(document, currentWordSelection)) {
        return null; // NOSONAR
    }

    /* Charge le type Java. */
    IType javaType = findJavaType(currentWord);
    if (javaType == null) {
        return null; // NOSONAR
    }

    /* Renvoie un lien pour ouvrir le type Java. */
    IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
    return new IHyperlink[] { new JavaTypeHyperLink(targetRegion, javaType) };
}
项目:Tarski    文件:MarkerMappingActionHyperlinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
    boolean canShowMultipleHyperlinks) {

  int offset = region.getOffset();
  int length = region.getLength();
  if (offset == 0 && length == 0)
    return null;

  if (MarkerActivator.getEditor() == null || MarkerActivator.getEditor().getEditorInput() == null)
    return null;

  IFile file = (IFile) MarkerActivator.getEditor().getEditorInput().getAdapter(IFile.class);

  List<IMarker> markedList = MarkerFactory.findMarkers(file);
  for (IMarker iMarker : markedList) {
    // look for keyword
    // detect region containing keyword
    IRegion targetRegion = new Region(MarkUtilities.getStart(iMarker),
        MarkUtilities.getLength(iMarker));
    if ((targetRegion.getOffset() <= offset)
        && ((targetRegion.getOffset() + targetRegion.getLength()) > offset)) {
      // create link
      return new IHyperlink[] {new MarkerMappingActionHyperlink(targetRegion)};
    }
  }
  return null;
}
项目:egradle    文件:GradleHyperlinkDetector.java   
private IHyperlink[] handlerResourceLink(ITextViewer textViewer, IRegion lineInfo, GradleHyperLinkResult result) {
    try {
        IRegion urlRegion = new Region(lineInfo.getOffset() + result.linkOffsetInLine, result.linkLength);
        IDocument document = textViewer.getDocument();
        String fullText = null;
        if (document!=null){
            fullText= document.get();
        }
        GradleResourceHyperlink gradleResourceLink = new GradleResourceHyperlink(urlRegion, result.linkContent, fullText);
        return new IHyperlink[] { gradleResourceLink };
    } catch (RuntimeException e) {
        return null;
    }
}
项目:DarwinSPL    文件:DwprofileHyperlinkDetector.java   
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    de.darwinspl.preferences.resource.dwprofile.IDwprofileLocationMap locationMap = textResource.getLocationMap();
    List<EObject> elementsAtOffset = locationMap.getElementsAt(region.getOffset());
    EObject resolvedEObject = null;
    for (EObject eObject : elementsAtOffset) {
        if (eObject.eIsProxy()) {
            resolvedEObject = EcoreUtil.resolve(eObject, textResource);
            if (resolvedEObject == eObject) {
                continue;
            }
            int offset = locationMap.getCharStart(eObject);
            int length = locationMap.getCharEnd(eObject) - offset + 1;
            String text = null;
            try {
                text = textViewer.getDocument().get(offset, length);
            } catch (BadLocationException e) {
            }
            // we skip elements that are not contained in a resource, because we cannot jump
            // to them anyway
            if (resolvedEObject.eResource() != null) {
                IHyperlink hyperlink = new de.darwinspl.preferences.resource.dwprofile.ui.DwprofileHyperlink(new Region(offset, length), resolvedEObject, text);
                return new IHyperlink[] {hyperlink};
            }
        }
    }
    return null;
}
项目:DarwinSPL    文件:HyexpressionHyperlinkDetector.java   
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    eu.hyvar.feature.expression.resource.hyexpression.IHyexpressionLocationMap locationMap = textResource.getLocationMap();
    List<EObject> elementsAtOffset = locationMap.getElementsAt(region.getOffset());
    EObject resolvedEObject = null;
    for (EObject eObject : elementsAtOffset) {
        if (eObject.eIsProxy()) {
            resolvedEObject = EcoreUtil.resolve(eObject, textResource);
            if (resolvedEObject == eObject) {
                continue;
            }
            int offset = locationMap.getCharStart(eObject);
            int length = locationMap.getCharEnd(eObject) - offset + 1;
            String text = null;
            try {
                text = textViewer.getDocument().get(offset, length);
            } catch (BadLocationException e) {
            }
            // we skip elements that are not contained in a resource, because we cannot jump
            // to them anyway
            if (resolvedEObject.eResource() != null) {
                IHyperlink hyperlink = new eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionHyperlink(new Region(offset, length), resolvedEObject, text);
                return new IHyperlink[] {hyperlink};
            }
        }
    }
    return null;
}
项目:DarwinSPL    文件:HyvalidityformulaHyperlinkDetector.java   
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    eu.hyvar.context.contextValidity.resource.hyvalidityformula.IHyvalidityformulaLocationMap locationMap = textResource.getLocationMap();
    List<EObject> elementsAtOffset = locationMap.getElementsAt(region.getOffset());
    EObject resolvedEObject = null;
    for (EObject eObject : elementsAtOffset) {
        if (eObject.eIsProxy()) {
            resolvedEObject = EcoreUtil.resolve(eObject, textResource);
            if (resolvedEObject == eObject) {
                continue;
            }
            int offset = locationMap.getCharStart(eObject);
            int length = locationMap.getCharEnd(eObject) - offset + 1;
            String text = null;
            try {
                text = textViewer.getDocument().get(offset, length);
            } catch (BadLocationException e) {
            }
            // we skip elements that are not contained in a resource, because we cannot jump
            // to them anyway
            if (resolvedEObject.eResource() != null) {
                IHyperlink hyperlink = new eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaHyperlink(new Region(offset, length), resolvedEObject, text);
                return new IHyperlink[] {hyperlink};
            }
        }
    }
    return null;
}
项目:DarwinSPL    文件:HydatavalueHyperlinkDetector.java   
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    eu.hyvar.dataValues.resource.hydatavalue.IHydatavalueLocationMap locationMap = textResource.getLocationMap();
    List<EObject> elementsAtOffset = locationMap.getElementsAt(region.getOffset());
    EObject resolvedEObject = null;
    for (EObject eObject : elementsAtOffset) {
        if (eObject.eIsProxy()) {
            resolvedEObject = EcoreUtil.resolve(eObject, textResource);
            if (resolvedEObject == eObject) {
                continue;
            }
            int offset = locationMap.getCharStart(eObject);
            int length = locationMap.getCharEnd(eObject) - offset + 1;
            String text = null;
            try {
                text = textViewer.getDocument().get(offset, length);
            } catch (BadLocationException e) {
            }
            // we skip elements that are not contained in a resource, because we cannot jump
            // to them anyway
            if (resolvedEObject.eResource() != null) {
                IHyperlink hyperlink = new eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavalueHyperlink(new Region(offset, length), resolvedEObject, text);
                return new IHyperlink[] {hyperlink};
            }
        }
    }
    return null;
}
项目:DarwinSPL    文件:HymappingHyperlinkDetector.java   
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    eu.hyvar.feature.mapping.resource.hymapping.IHymappingLocationMap locationMap = textResource.getLocationMap();
    List<EObject> elementsAtOffset = locationMap.getElementsAt(region.getOffset());
    EObject resolvedEObject = null;
    for (EObject eObject : elementsAtOffset) {
        if (eObject.eIsProxy()) {
            resolvedEObject = EcoreUtil.resolve(eObject, textResource);
            if (resolvedEObject == eObject) {
                continue;
            }
            int offset = locationMap.getCharStart(eObject);
            int length = locationMap.getCharEnd(eObject) - offset + 1;
            String text = null;
            try {
                text = textViewer.getDocument().get(offset, length);
            } catch (BadLocationException e) {
            }
            // we skip elements that are not contained in a resource, because we cannot jump
            // to them anyway
            if (resolvedEObject.eResource() != null) {
                IHyperlink hyperlink = new eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingHyperlink(new Region(offset, length), resolvedEObject, text);
                return new IHyperlink[] {hyperlink};
            }
        }
    }
    return null;
}