當前位置: 首頁>>代碼示例>>Java>>正文


Java ITextSelection.getText方法代碼示例

本文整理匯總了Java中org.eclipse.jface.text.ITextSelection.getText方法的典型用法代碼示例。如果您正苦於以下問題:Java ITextSelection.getText方法的具體用法?Java ITextSelection.getText怎麽用?Java ITextSelection.getText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jface.text.ITextSelection的用法示例。


在下文中一共展示了ITextSelection.getText方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCurrentEditorCurrentWord

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
public static String getCurrentEditorCurrentWord(WordSelectionType wordSelectionType) {
	IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

	/* Extrait l'éditeur courant. */
	ITextEditor editor = (ITextEditor) activePage.getActiveEditor();
	if (editor == null) {
		return null;
	}

	/* Extrait la sélection courante. */
	ITextSelection selection = (ITextSelection) activePage.getSelection();
	if (selection == null) {
		return null;
	}

	/* Extrait le document courant. */
	IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

	/* Extrait le mot sélectionné. */
	ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, wordSelectionType);
	if (currentWordSelection == null) {
		return null;
	}

	return currentWordSelection.getText();
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:27,代碼來源:UiUtils.java

示例2: getHoverRegion

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {

	IDocument document = textViewer.getDocument();

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

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

	/* Renvoie la région du mot. */
	return new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:26,代碼來源:KspTextHover.java

示例3: retrieveSelection

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
private static String retrieveSelection(IWorkbenchPart targetPart) {
  ISelection targetSelection = getTargetSelection(targetPart);
  if (targetSelection instanceof ITextSelection) {
    ITextSelection ts = (ITextSelection) targetSelection;
    String text = ts.getText();
    if (textHasContent(text)) {
      return text;
    } else if (targetPart instanceof IEditorPart) {
      IEditorPart editor = (IEditorPart) targetPart;
      if (editor instanceof ITextEditor) {
        return extractSurroundingWord(ts, (ITextEditor) editor);
      }
    }
  }
  return null;
}
 
開發者ID:jbosstools,項目名稱:chromedevtools,代碼行數:17,代碼來源:JsInspectSnippetAction.java

示例4: computeCompletionProposals

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer textViewer, int documentOffset) {
	IDocument document = textViewer.getDocument();

	/* Extrait le mot courant en snake-case pour tolérer les minuscules. */
	ITextSelection selection = new TextSelection(document, documentOffset - 1, 1);
	ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, getWordSelectionType());
	if (currentWordSelection == null) {
		return null; // NOSONAR
	}
	String currentWord = currentWordSelection.getText();
	if (currentWord == null || !isCurrentWordValid(currentWord)) {
		return null; // NOSONAR
	}

	/* Charge tous les domaines candidats. */
	List<CompletionCandidate> candidates = getCandidates(currentWordSelection);
	/* Filtre la liste des candidats avec le mot courant. */
	List<CompletionCandidate> suggestions = filterSuggestions(candidates, currentWord);

	/* Cas sans suggestions. */
	if (suggestions.isEmpty()) {
		return null; // NOSONAR
	}

	/* Construit le résultat. */
	try {
		return buildProposals(suggestions, currentWordSelection);
	} catch (Exception e) {
		ErrorUtils.handle(e);
	}

	return null; // NOSONAR
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:35,代碼來源:BaseContentAssistProcessor.java

示例5: detectHyperlinks

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@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
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:36,代碼來源:SqlTableHyperLinkDetector.java

示例6: detectHyperlinks

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@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) };
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:33,代碼來源:FilePathHyperLinkDetector.java

示例7: detectHyperlinks

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@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);
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:34,代碼來源:KspNameHyperLinkDetector.java

示例8: detectHyperlinks

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@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) };
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:37,代碼來源:DtoDefinitionPathHyperLinkDetector.java

示例9: detectHyperlinks

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@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) };
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:31,代碼來源:CanonicalJavaNameHyperLinkDetector.java

示例10: getCurrentSelection

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
private static String getCurrentSelection() {
	IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
	if (part instanceof ITextEditor) {
		final ITextEditor editor = (ITextEditor) part;
		IDocumentProvider prov = editor.getDocumentProvider();
		IDocument doc = prov.getDocument(editor.getEditorInput());
		ISelection sel = editor.getSelectionProvider().getSelection();
		if (sel instanceof TextSelection) {
			ITextSelection textSel = (ITextSelection) sel;
			return textSel.getText();
		}
	}
	return null;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:15,代碼來源:TraceToCodeUIAction.java

示例11: detectHyperlinks

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {

	/* Cas d'un fichier .class : on ne traite pas car le fichier n'est pas dans le projet. */
	boolean isClassFile = !textViewer.isEditable();
	if (isClassFile) {
		return null; // NOSONAR
	}

	IDocument document = textViewer.getDocument();

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

	/* Cherche une déclaration KSP correspondant au nom Java. */
	KspDeclaration kspDeclaration = KspManager.getInstance().findKspDeclaration(currentWord);
	if (kspDeclaration == null) {
		return null; // NOSONAR
	}

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

	/* Construit le lien vers la déclaration KSP. */
	IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
	hyperLinks.add(new KspDeclarationHyperLink(targetRegion, kspDeclaration));

	/* Cherche si l'implémentation KSP est une méthode de DAO. */
	DaoImplementation daoImplementation = DaoManager.getInstance().findDaoImplementation(currentWord);
	if (daoImplementation != null) {
		/* Cherche si la méthode de DAO possède une classe de test unitaire. */
		JavaClassFile testClass = JavaClassManager.getInstance().findJavaClassTest(daoImplementation);
		if (testClass != null) {
			/* Ajoute en premier le lien pour que le lien principal vers le KSP soit en dernier. */
			hyperLinks.add(0, new JavaTestClassHyperLink(targetRegion, testClass));
		}
	}

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

	/* On retourne les liens de la Task. */
	return hyperLinks.toArray(new IHyperlink[0]);
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:53,代碼來源:KspImplementationHyperLinkDetector.java

示例12: computeCharacterPosition

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
 * Computes the next insert position of the given character in the current line.
 *
 * @param document the document we are working on
 * @param line the line where the change is being made
 * @param offset the position of the caret in the line when <code>character</code> was typed
 * @param character the character to look for
 * @param partitioning the document partitioning
 * @return the position where <code>character</code> should be inserted / replaced
 */
protected static int computeCharacterPosition(IDocument document, ITextSelection line, int offset, char character,
		String partitioning) {
	String text = line.getText();
	if (text == null) return 0;

	int insertPos;
	if (character == BRACECHAR) {

		insertPos = computeArrayInitializationPos(document, line, offset, partitioning);

		if (insertPos == -1) {
			insertPos = computeAfterTryDoElse(document, line, offset);
		}

		if (insertPos == -1) {
			insertPos = computeAfterParenthesis(document, line, offset, partitioning);
		}

	} else if (character == SEMICHAR) {

		if (isForStatement(text, offset)) {
			insertPos = -1; // don't do anything in for statements, as semis are vital part of
							 // these
		} else {
			int nextPartitionPos = nextPartitionOrLineEnd(document, line, offset, partitioning);
			insertPos = startOfWhitespaceBeforeOffset(text, nextPartitionPos);
			// if there is a semi present, return its location as alreadyPresent() will take it
			// out this way.
			if (insertPos > 0 && text.charAt(insertPos - 1) == character)
				insertPos = insertPos - 1;
			else if (insertPos > 0 && text.charAt(insertPos - 1) == '}') {
				int opening = scanBackward(document, insertPos - 1 + line.getOffset(), partitioning, -1,
						new char[] { '{' });
				if (opening > -1 && opening < offset + line.getOffset()) {
					if (computeArrayInitializationPos(document, line, opening - line.getOffset(),
							partitioning) == -1) {
						insertPos = offset;
					}
				}
			}
		}

	} else {
		Assert.isTrue(false);
		return -1;
	}

	return insertPos;
}
 
開發者ID:grosenberg,項目名稱:fluentmark,代碼行數:60,代碼來源:SmartAutoEditStrategy.java

示例13: computeCompletionProposals

import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
 * Override improves matching accuracy
 */
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {

	ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();

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

	String prefix = extractPrefix(viewer, offset);
	Region region = new Region(offset - prefix.length(), prefix.length());
	TemplateContext context = createContext(viewer, region);
	if (context == null) {
		return new ICompletionProposal[0];
	}
	Region selectionRegion = new Region(selection.getOffset(), selection.getLength());
	TemplateContext selectionContext = createContext(viewer, selectionRegion);

	int lineOffset = 0;
	try {
		IRegion lineInformationOfOffset = viewer.getDocument().getLineInformationOfOffset(offset);
		lineOffset = offset - lineInformationOfOffset.getOffset();
	} catch (BadLocationException e1) {}

	String selectionText = selection.getText();
	context.setVariable("selection", selectionText); //$NON-NLS-1$
	selectionContext.setVariable("selection", selectionText); //$NON-NLS-1$
	context.setVariable("text", selectionText); //$NON-NLS-1$
	selectionContext.setVariable("text", selectionText); //$NON-NLS-1$

	Template[] templates = getTemplates(context.getContextType().getId());

	List<ICompletionProposal> matches = new ArrayList<ICompletionProposal>(templates.length);
	for (Template template : templates) {
		try {
			context.getContextType().validate(template.getPattern());
		} catch (TemplateException e) {
			continue;
		}
		if (!template.matches(prefix, context.getContextType().getId())) {
			continue;
		}
		boolean selectionBasedMatch = isSelectionBasedMatch(template, context);
		if (template.getName().startsWith(prefix) || selectionBasedMatch) {

			int relevance = getRelevance(template, lineOffset, prefix);
			if (selectionBasedMatch) {
				matches.add(createProposal(template, selectionContext, (IRegion) selectionRegion, relevance));
			} else {
				matches.add(createProposal(template, context, (IRegion) region, relevance));
			}
		}
	}

	Collections.sort(matches, proposalComparator);

	return matches.toArray(new ICompletionProposal[matches.size()]);
}
 
開發者ID:grosenberg,項目名稱:fluentmark,代碼行數:63,代碼來源:FluentMkTemplateCompletionProcessor.java


注:本文中的org.eclipse.jface.text.ITextSelection.getText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。