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


Java IDocument.getChar方法代碼示例

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


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

示例1: extractPrefix

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
@Override
protected String extractPrefix(ITextViewer viewer, int offset) {
    int i = offset;
    IDocument document = viewer.getDocument();
    if (i > document.getLength()) {
        return ""; //$NON-NLS-1$
    }
    try {
        while (i > 0) {
            char ch = document.getChar(i - 1);
            if (!PgDiffUtils.isValidIdChar(ch)) {
                break;
            }
            i--;
        }
        if (i > 0) {
            int j = i;
            if (document.getChar(j - 1) == '<') {
                i--;
            }
        }
        return document.get(i, offset - i);
    } catch (BadLocationException e) {
        return ""; //$NON-NLS-1$
    }
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:27,代碼來源:SQLEditorTemplateAssistProcessor.java

示例2: findCharReverse

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
private int findCharReverse(char c, IDocument doc, int offset) {
	try {
		while (offset-- > 0) {
			char current = doc.getChar(offset);
			if (current == c)
				return offset;
		}
		return -1;
	} catch (BadLocationException e) {
		// TODO Auto-generated catch block
		return -1;
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:14,代碼來源:CtfCompletionProposalsComputer.java

示例3: computeCompletionProposals

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
@Override
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context,
		IProgressMonitor monitor) {
	String prefix = "";
	try {
		if (context != null) {
			prefix = context.computeIdentifierPrefix().toString();

			String tmpPrefix = "";
			IDocument doc = context.getDocument();
			if ((!prefix.equals("")) || (doc.get().length() == 0)) {
				tmpPrefix = prefix;
			} else {
				int offset = context.getInvocationOffset();
				if (doc.getChar(offset - 1) == '.') {
					tmpPrefix = ".";
					if (offset >= CONTEXT_PREFIX.length()
							&& doc.get(offset - CONTEXT_PREFIX.length(), CONTEXT_PREFIX.length()).equals(
									CONTEXT_PREFIX)) {
						tmpPrefix = CONTEXT_PREFIX;
					}
				}
			}
			prefix = tmpPrefix;

		}
	} catch (BadLocationException e) {
		throw new RuntimeException(e);
	}

	return computeCompletionProposals(context.getViewer(), prefix, context.getInvocationOffset(), monitor);
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:33,代碼來源:HydrographCompletionProposalComputer.java

示例4: isInsertClosingBracket

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
@Override
public boolean isInsertClosingBracket(IDocument doc, int offset) throws BadLocationException {
	if (doc.getLength() <= offset)
		return true;
	char charAtOffset = doc.getChar(offset);
	boolean result = !Character.isDigit(charAtOffset);
	return result;
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:9,代碼來源:IntStrategyPredicate.java

示例5: computeCompletionProposals

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
	final List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
	try {
		final IDocument document = viewer.getDocument();
		Character c = document.getChar(offset - 1);
		int temp = offset - 1;
		String s = "";

		if (Character.isAlphabetic(c)) {
			while (Character.isAlphabetic(c)) {
				s += c;
				temp--;
				c = document.getChar(temp);
			}
			s = new StringBuilder(s).reverse().toString();

			for (int i = 0; i < FormulasScanner.formulasKeywords.length; i++) {
				if (FormulasScanner.formulasKeywords[i].startsWith(s)) {
					proposals.add(new CompletionProposal(FormulasScanner.formulasKeywords[i], temp + 1, s.length(),
							FormulasScanner.formulasKeywords[i].length()));
				}
			}
		} else if (c == '(') {
			document.replace(temp, 1, "()");
		} else if (c == '[') {
			document.replace(temp, 1, "[]");
		}

		if (proposals.isEmpty() && s == "") {
			for (int i = 0; i < FormulasScanner.formulasKeywords.length; i++) {
				proposals.add(new CompletionProposal(FormulasScanner.formulasKeywords[i], temp + 1, s.length(),
						FormulasScanner.formulasKeywords[i].length()));
			}
		}

	} catch (final BadLocationException e) {
		e.printStackTrace();
	}
	final ICompletionProposal[] result = new ICompletionProposal[proposals.size()];
	proposals.toArray(result);
	return result;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:44,代碼來源:CodeCompletionProcessor.java

示例6: computeCompletionProposals

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

  final List<ICompletionProposal> proposals = new ArrayList<>();
  try {
    final IDocument document = viewer.getDocument();

    // we try to find the prefix of keyword which is edited in text.
    // we look from last to first offset, if the 'c' is non-alphabetic then stop.
    // Ex: if user write "{on" we take "on" then search the keywords which are acceptable for this
    // prefix.
    Character c = document.getChar(offset - 1);
    int temp = offset - 1;
    String s = "";

    if (Character.isAlphabetic(c)) {
      while (Character.isAlphabetic(c)) {
        s += c;
        temp--;
        c = document.getChar(temp);
      }
      s = new StringBuilder(s).reverse().toString();

      for (int i = 0; i < SentencesScanner.keywords.length; i++) {
        if (SentencesScanner.keywords[i].startsWith(s)) {
          proposals.add(new CompletionProposal(SentencesScanner.keywords[i], temp + 1, s.length(),
              SentencesScanner.keywords[i].length()));
        }
      }

      for (final String relationName : ValidationEditor.getRelationNames()) {
        if (relationName.toLowerCase().startsWith(s.toLowerCase())) {
          proposals.add(
              new CompletionProposal(relationName, temp + 1, s.length(), relationName.length()));
        }
      }

      for (final String atomName : ValidationEditor.getAtomNames()) {
        if (atomName.toLowerCase().startsWith(s.toLowerCase())) {
          proposals
              .add(new CompletionProposal(atomName, temp + 1, s.length(), atomName.length()));
        }
      }
    }

    // proposals list is still empty, ok then give all keywords like java does.
    if (proposals.isEmpty()) {
      for (int i = 0; i < SentencesScanner.keywords.length; i++) {
        proposals.add(new CompletionProposal(SentencesScanner.keywords[i], temp + 1, s.length(),
            SentencesScanner.keywords[i].length()));
      }
    }
  } catch (final BadLocationException e) {
    e.printStackTrace();
  }
  final ICompletionProposal[] result = new ICompletionProposal[proposals.size()];
  proposals.toArray(result);
  return result;

}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:62,代碼來源:DefaultCompletionProcessor.java

示例7: computeCompletionProposals

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer,
    final int offset) {
  final List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
  try {
    final IDocument document = viewer.getDocument();
    Character c = document.getChar(offset - 1);
    int temp = offset - 1;
    String s = "";

    if (Character.isAlphabetic(c)) {
      while (Character.isAlphabetic(c)) {
        s += c;
        temp--;
        c = document.getChar(temp);
      }
      s = new StringBuilder(s).reverse().toString();

      for (int i = 0; i < CodeScanner.keywords.length; i++) {
        if (CodeScanner.keywords[i].startsWith(s)) {
          proposals.add(new CompletionProposal(CodeScanner.keywords[i], temp + 1, s.length(),
              CodeScanner.keywords[i].length()));
        }
      }
    } else if (c == '(') {
      document.replace(temp, 1, "()");
    } else if (c == '{') {
      document.replace(temp, 1, "{\n\n}");
    }

    if (proposals.isEmpty() && s == "") {
      for (int i = 0; i < CodeScanner.keywords.length; i++) {
        proposals.add(new CompletionProposal(CodeScanner.keywords[i], temp + 1, s.length(),
            CodeScanner.keywords[i].length()));
      }
    }

  } catch (final BadLocationException e) {
    e.printStackTrace();
  }
  final ICompletionProposal[] result = new ICompletionProposal[proposals.size()];
  proposals.toArray(result);
  return result;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:45,代碼來源:CodeCompletionProcessor.java

示例8: computeCompletionProposals

import org.eclipse.jface.text.IDocument; //導入方法依賴的package包/類
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer,
    final int offset) {
  final List<ICompletionProposal> proposals = new ArrayList<>();
  try {
    final IDocument document = viewer.getDocument();

    // we try to find the prefix of keyword which is edited in text.
    // we look from last to first offset, if the 'c' is non-alphabetic then stop.
    // Ex: if user write "{on" we take "on" then search the keywords which are acceptable for this
    // prefix.
    Character c = document.getChar(offset - 1);
    int temp = offset - 1;
    StringBuilder builder = new StringBuilder();

    if (Character.isAlphabetic(c)) {
      while (Character.isAlphabetic(c)) {
        builder.append(c);
        temp--;
        c = document.getChar(temp);
      }
      builder = builder.reverse();

      for (int i = 0; i < DefaultScanner.keywords.length; i++) {
        if (DefaultScanner.keywords[i].startsWith(builder.toString())) {
          proposals.add(new CompletionProposal(DefaultScanner.keywords[i], temp + 1,
              builder.length(), DefaultScanner.keywords[i].length()));
        }
      }
    } else {
      // if the last edited char is non-alphabetic then may be user wants the relation list.
      for (int i = 0; i < this.activationChars.length; i++) {
        if (this.activationChars[i] == c) {
          for (final String rel : AlloyParserForMetamodel.getRels()) {
            proposals.add(new CompletionProposal(rel, temp + 1, builder.length(), rel.length()));
          }
          break;
        }
      }
    }
  } catch (final BadLocationException e) {
    e.printStackTrace();
  }
  final ICompletionProposal[] result = new ICompletionProposal[proposals.size()];
  proposals.toArray(result);
  return result;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:48,代碼來源:DefaultCompletionProcessor.java


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