org.eclipse.jface.text.IDocument#DEFAULT_CONTENT_TYPE源码实例Demo

下面列出了org.eclipse.jface.text.IDocument#DEFAULT_CONTENT_TYPE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public IContentAssistant getContentAssistant(final ISourceViewer sourceViewer) {
    // returns only Groovy-approved completion proposal categories
    ContentAssistant assistant = (ContentAssistant) super.getContentAssistant(sourceViewer);
    assistant.enableAutoActivation(true);
    assistant.setStatusLineVisible(false);

    // retain only contract input categories
    final ExtendedJavaCompletionProcessor processor = new ExtendedJavaCompletionProcessor(getEditor(), assistant,
            IDocument.DEFAULT_CONTENT_TYPE);
    assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
    List<CompletionProposalCategory> categories = (List<CompletionProposalCategory>) ReflectionUtils
            .getPrivateField(ContentAssistProcessor.class, "fCategories", processor);

    ReflectionUtils.setPrivateField(ContentAssistProcessor.class, "fCategories", processor, categories.stream()
            .filter(category -> Objects.equals(category.getId(), CONSTRAINT_CONTENT_ASSIST_CATEGORY_ID))
            .collect(Collectors.toList()));

    ContentAssistPreference.configure(assistant, fPreferenceStore);

    return assistant;
}
 
/**
 * Installs a java partitioner with <code>document</code>.
 *
 * @param document the document
 */
private static void installJavaStuff(Document document) {
	String[] types= new String[] {
								  IJavaScriptPartitions.JAVA_DOC,
								  IJavaScriptPartitions.JAVA_MULTI_LINE_COMMENT,
								  IJavaScriptPartitions.JAVA_SINGLE_LINE_COMMENT,
								  IJavaScriptPartitions.JAVA_STRING,
								  IJavaScriptPartitions.JAVASCRIPT_TEMPLATE_LITERAL,
								  IJavaScriptPartitions.JAVA_CHARACTER,
								  IJSXPartitions.JSX,
								  IDocument.DEFAULT_CONTENT_TYPE
	};
	FastPartitioner partitioner= new FastPartitioner(new FastTypeScriptPartitionScanner(), types);
	partitioner.connect(document);
	document.setDocumentPartitioner(IJavaScriptPartitions.JAVA_PARTITIONING, partitioner);
}
 
源代码3 项目: APICloud-Studio   文件: ContentAssistant.java
/**
 * Returns the code assist processor for the content type of the specified document position.
 * 
 * @param contentAssistSubjectControl
 *            the code assist subject control
 * @param offset
 *            a offset within the document
 * @return a content-assist processor or <code>null</code> if none exists
 * @since 3.0
 */
private IContentAssistProcessor getProcessor(IContentAssistSubjectControl contentAssistSubjectControl, int offset)
{
	try
	{

		IDocument document = contentAssistSubjectControl.getDocument();
		String type;
		if (document != null)
		{
			type = TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true);
		}
		else
		{
			type = IDocument.DEFAULT_CONTENT_TYPE;
		}

		return getContentAssistProcessor(type);

	}
	catch (BadLocationException x)
	{
	}

	return null;
}
 
源代码4 项目: Pydev   文件: PartitionCodeReaderTest.java
public void testPartitionCodeReaderMarkBackwards2() throws Exception {
    PartitionCodeReader reader = new PartitionCodeReader(IDocument.DEFAULT_CONTENT_TYPE);
    Document document = new Document("abcde");
    String category = setupDocument(document);

    document.addPosition(category, new TypedPosition(0, 1, "cat1")); //skip a
    document.addPosition(category, new TypedPosition(2, 1, "cat1")); //skip c
    document.addPosition(category, new TypedPosition(4, 1, "cat1")); //skip e

    reader.configureBackwardReader(document, document.getLength());
    int mark = reader.getMark();
    assertEquals(reader.read(), 'd');

    int mark2 = reader.getMark();
    assertEquals(reader.read(), 'b');

    int mark3 = reader.getMark();
    assertEquals(reader.read(), -1);

    reader.setMark(mark);
    assertEquals(reader.read(), 'd');
    assertEquals(reader.read(), 'b');
    assertEquals(reader.read(), -1);

    reader.setMark(mark2);
    assertEquals(reader.read(), 'b');
    assertEquals(reader.read(), -1);

    reader.setMark(mark3);
    assertEquals(reader.read(), -1);
}
 
源代码5 项目: http4e   文件: HConfiguration.java
public String[] getConfiguredContentTypes( ISourceViewer sourceViewer){
   return new String[] { 
         IDocument.DEFAULT_CONTENT_TYPE,  
         HPartitionScanner.COMMENT,
         HPartitionScanner.PROPERTY_VALUE,
         /*HPartitionScanner.PROPERTY_KEY,*/ };
}
 
@Override
protected int getLineStartPosition(final IDocument document, final String line, final int length, final int offset) {

	String type= IDocument.DEFAULT_CONTENT_TYPE;
	try {
		type= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, offset, true);
	} catch (BadLocationException exception) {
		// Should not happen
	}

	int index= super.getLineStartPosition(document, line, length, offset);
	if (type.equals(IJavaPartitions.JAVA_DOC) || type.equals(IJavaPartitions.JAVA_MULTI_LINE_COMMENT)) {
		if (index < length - 1 && line.charAt(index) == '*' && line.charAt(index + 1) != '/') {
			do {
				++index;
			} while (index < length && Character.isWhitespace(line.charAt(index)));
		}
	} else {
		if (index < length - 1 && line.charAt(index) == '/' && line.charAt(index + 1) == '/') {
			index++;
			do {
				++index;
			} while (index < length && Character.isWhitespace(line.charAt(index)));
		}
	}
	return index;
}
 
源代码7 项目: xtext-eclipse   文件: XtextEditor.java
@Override
protected int getLineStartPosition(final IDocument document, final String line, final int length,
		final int offset) {

	String type = IDocument.DEFAULT_CONTENT_TYPE;
	try {
		type = TextUtilities.getContentType(document, IDocumentExtension3.DEFAULT_PARTITIONING, offset, false);
	} catch (BadLocationException exception) {
		// Should not happen
	}

	int lineStartPosition = super.getLineStartPosition(document, line, length, offset);
	if (tokenTypeToPartitionTypeMapperExtension.isMultiLineComment(type)
			|| tokenTypeToPartitionTypeMapperExtension.isSingleLineComment(type)) {
		try {
			IRegion lineInformation = document.getLineInformationOfOffset(offset);
			int offsetInLine = offset - lineInformation.getOffset();
			return getCommentLineStartPosition(line, length, offsetInLine, lineStartPosition);
		} catch(BadLocationException e) {
			// Should not happen
		}
	} 
	if (type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {
		if (isStartOfSingleLineComment(line, length, lineStartPosition) && !isStartOfMultiLineComment(line, length, lineStartPosition)) {
			return getTextStartPosition(line, length, lineStartPosition + 1);
		}
	}
	return lineStartPosition;
}
 
/**
 * Creates the partitioner and sets up the appropriate rules.
 */
public EditorConfigPartitionScanner() {
	super();

	IToken comment = new Token(COMMENT);
	IToken sectionName = new Token(SECTION);
	IToken propertyValue = new Token(PROPERTY_VALUE);
	IToken key = new Token(IDocument.DEFAULT_CONTENT_TYPE);

	List<IPredicateRule> rules = new ArrayList<IPredicateRule>();

	// Add rule for leading white space.
	rules.add(new LeadingWhitespacePredicateRule(key, "\t")); //$NON-NLS-1$
	rules.add(new LeadingWhitespacePredicateRule(key, " ")); //$NON-NLS-1$

	// Add rules for comments.
	rules.add(new EndOfLineRule("#", comment, (char) 0, true)); //$NON-NLS-1$
	// rules.add(new EndOfLineRule("!", comment, (char) 0, true));
	// //$NON-NLS-1$

	// Add rules for sections.
	rules.add(new SingleLineRule("[", "]", sectionName, '\\', true, true)); //$NON-NLS-1$

	// Add rules for property values.
	rules.add(new SingleLineRule("=", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule(":", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule(" ", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule("\t", null, propertyValue, '\\', true, true)); //$NON-NLS-1$

	// Add special case word rule.
	EmptyCommentRule wordRule = new EmptyCommentRule(comment);
	rules.add(wordRule);

	IPredicateRule[] result = new IPredicateRule[rules.size()];
	rules.toArray(result);
	setPredicateRules(result);
}
 
/**
 * Creates the partitioner and sets up the appropriate rules.
 */
public PropertiesFilePartitionScanner() {
	super();

	IToken comment= new Token(COMMENT);
	IToken propertyValue= new Token(PROPERTY_VALUE);
	IToken key= new Token(IDocument.DEFAULT_CONTENT_TYPE);

	List<IPredicateRule> rules= new ArrayList<IPredicateRule>();

	// Add rule for leading white space.
	rules.add(new LeadingWhitespacePredicateRule(key, "\t")); //$NON-NLS-1$
	rules.add(new LeadingWhitespacePredicateRule(key, " ")); //$NON-NLS-1$

	// Add rules for comments.
	rules.add(new EndOfLineRule("#", comment, (char) 0, true)); //$NON-NLS-1$
	rules.add(new EndOfLineRule("!", comment, (char) 0, true)); //$NON-NLS-1$

	// Add rules for property values.
	rules.add(new SingleLineRule("=", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule(":", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule(" ", null, propertyValue, '\\', true, true)); //$NON-NLS-1$
	rules.add(new SingleLineRule("\t", null, propertyValue, '\\', true, true)); //$NON-NLS-1$

	// Add special case word rule.
	EmptyCommentRule wordRule= new EmptyCommentRule(comment);
	rules.add(wordRule);

	IPredicateRule[] result= new IPredicateRule[rules.size()];
	rules.toArray(result);
	setPredicateRules(result);
}
 
源代码10 项目: birt   文件: SQLSourceViewerConfiguration.java
@Override
public String[] getConfiguredContentTypes( ISourceViewer sourceViewer )
{
	return new String[]{
			SQLPartitionScanner.QUOTE_STRING,
			SQLPartitionScanner.COMMENT,
			IDocument.DEFAULT_CONTENT_TYPE };
}
 
@Override
public String getContentType(int offset) {
	
	try {
		IRegion lineInfo = fDocument.getLineInformationOfOffset(offset);
		String line = fDocument.get(lineInfo.getOffset(), lineInfo.getLength());
		
		if (line.startsWith("INSERT ") || line.startsWith("INSERT_UPDATE ") || line.startsWith("UPDATE ") || line.startsWith("REMOVE ")) {
			return ImpexDocumentPartitioner.IMPEX_HEADER;
		}
		if (line.startsWith("\"#%") || line.startsWith("#%")) {
			return ImpexDocumentPartitioner.IMPEX_INSTRUCTION;
		}
		if (line.startsWith("#")) {
			return ImpexDocumentPartitioner.IMPEX_COMMENT;
		}
		if (line.startsWith(";")) {
			return ImpexDocumentPartitioner.IMPEX_DATA;
		}
		if (line.startsWith("$")) {
			//TODO - handle macros, user rights $START_USERRIGHTS
			return null;
		}
	}
	catch (BadLocationException e) {
		Activator.logError("BadLocationException", e);
	}
	
	return IDocument.DEFAULT_CONTENT_TYPE;
}
 
@Override
protected String calculateId(String tokenName, int tokenType) {
	/**
	 * The DOT grammar uses the 'terminal STRING' rule for unquoted text
	 * (that is usually used for quoted text) and uses the 'terminal
	 * QUOTED_STRING' rule for quoted text.
	 *
	 * With the default TerminalsTokenTypeToPartitionMapper, the double
	 * click text selection does not work as expected. It recognizes the
	 * unquoted text as quoted text (the first and the last letter will be
	 * stripped where they should not be stripped) and does not recognize
	 * the quoted text (the first and the last letter will not be stripped
	 * where they should be stripped).
	 *
	 * To fix this problem, assign the DEFAULT_CONTENT_TYPE to the 'terminal
	 * STRING' rule (identified by the 'RULE_STRING' token name) and the
	 * STRING_LITERAL_PARTITION to the 'terminal QUOTED_STRING' rule
	 * (identified by the 'RULE_QUOTED_STRING' token name).
	 */
	switch (tokenName) {
	case "RULE_STRING": //$NON-NLS-1$
		return IDocument.DEFAULT_CONTENT_TYPE;
	case "RULE_QUOTED_STRING": //$NON-NLS-1$
		return STRING_LITERAL_PARTITION;
	/**
	 * Html strings ('RULE_HTML_STRING') in dot use a specific syntax, hence
	 * for double clicking support, we need to implement a custom double
	 * click strategy using the HTML_STRING_PARTITION.
	 */
	case "RULE_HTML_STRING": //$NON-NLS-1$
		return HTML_STRING_PARTITION;
	default:
		return super.calculateId(tokenName, tokenType);
	}
}
 
@Override
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
	int length = IEditorConfigPartitions.PARTITIONS.length;
	String[] contentTypes = new String[length + 1];
	contentTypes[0] = IDocument.DEFAULT_CONTENT_TYPE;
	for (int i = 0; i < length; i++)
		contentTypes[i + 1] = IEditorConfigPartitions.PARTITIONS[i];

	return contentTypes;
}
 
源代码14 项目: Pydev   文件: PartitionCodeReaderTest.java
public void testPartitionCodeReaderUnread2() throws Exception {
    PartitionCodeReader reader = new PartitionCodeReader(IDocument.DEFAULT_CONTENT_TYPE);
    Document document = new Document("abcde");
    String category = setupDocument(document);

    document.addPosition(category, new TypedPosition(1, 1, "cat1")); //skip b
    document.addPosition(category, new TypedPosition(3, 1, "cat1")); //skip d

    reader.configureForwardReader(document, 0, document.getLength());
    FastStringBuffer buf = new FastStringBuffer(document.getLength());
    readAll(reader, buf);
    reader.unread(); //EOF
    reader.unread(); //e
    reader.unread(); //c
    readAll(reader, buf);
    reader.unread(); //EOF
    reader.unread(); //e
    reader.unread(); //c
    reader.unread(); //a
    readAll(reader, buf);
    reader.unread(); //EOF
    assertEquals(-1, reader.read());
    reader.unread(); //EOF
    reader.unread(); //e
    readAll(reader, buf);
    assertEquals("aceceacee", buf.toString());
}
 
源代码15 项目: Pydev   文件: ScriptConsolePartitioner.java
@Override
public ITypedRegion getPartition(int offset) {
    return new TypedRegion(offset, 1, IDocument.DEFAULT_CONTENT_TYPE);
}
 
@Override
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
	final MultiPassContentFormatter formatter= new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE);
	formatter.setMasterStrategy(new JavaFormattingStrategy());
	return formatter;
}
 
源代码17 项目: JAADAS   文件: JimpleConfiguration.java
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
	return new String[] {
		IDocument.DEFAULT_CONTENT_TYPE};
}
 
源代码18 项目: goclipse   文件: TextSettings_Actual.java
public String getId() {
	if(ordinal() == 0) {
		return IDocument.DEFAULT_CONTENT_TYPE;
	}
	return toString();
}
 
源代码19 项目: Pydev   文件: PartitionCodeReaderTest.java
public void testPartitionCodeReaderMark() throws Exception {
    PartitionCodeReader reader = new PartitionCodeReader(IDocument.DEFAULT_CONTENT_TYPE);
    Document document = new Document("abcde");
    String category = setupDocument(document);

    document.addPosition(category, new TypedPosition(1, 1, "cat1")); //skip b
    document.addPosition(category, new TypedPosition(3, 1, "cat1")); //skip d

    reader.configureForwardReader(document, 0, document.getLength());
    int mark = reader.getMark();
    assertEquals(0, mark);
    assertEquals(reader.read(), 'a');

    int mark2 = reader.getMark();
    assertEquals(1, mark2);
    assertEquals(reader.read(), 'c');

    int mark3 = reader.getMark();
    assertEquals(3, mark3);
    assertEquals(reader.read(), 'e');

    int mark4 = reader.getMark();
    assertEquals(5, mark4);
    assertEquals(reader.read(), -1);

    reader.setMark(mark);
    assertEquals(reader.read(), 'a');
    assertEquals(reader.read(), 'c');
    assertEquals(reader.read(), 'e');
    assertEquals(reader.read(), -1);

    reader.setMark(mark2);
    assertEquals(reader.read(), 'c');
    assertEquals(reader.read(), 'e');
    assertEquals(reader.read(), -1);

    reader.setMark(mark3);
    assertEquals(reader.read(), 'e');
    assertEquals(reader.read(), -1);

    reader.setMark(mark4);
    assertEquals(reader.read(), -1);
}
 
@Override
	public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
		if (getEditor() != null) {

			ContentAssistant assistant = new ContentAssistant();
			assistant.enableColoredLabels(true);
			assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));

			assistant.setRestoreCompletionProposalSize(getSettings("completion_proposal_size")); //$NON-NLS-1$

			IContentAssistProcessor javaProcessor = new TypeScriptCompletionProcessor(getEditor(), assistant,
					IDocument.DEFAULT_CONTENT_TYPE);
			assistant.setContentAssistProcessor(javaProcessor, IDocument.DEFAULT_CONTENT_TYPE);

			ContentAssistProcessor singleLineProcessor = new TypeScriptCompletionProcessor(getEditor(), assistant,
					IJavaScriptPartitions.JAVA_SINGLE_LINE_COMMENT);
			assistant.setContentAssistProcessor(singleLineProcessor, IJavaScriptPartitions.JAVA_SINGLE_LINE_COMMENT);

			ContentAssistProcessor stringProcessor = new TypeScriptCompletionProcessor(getEditor(), assistant,
					IJavaScriptPartitions.JAVA_STRING);
			assistant.setContentAssistProcessor(stringProcessor, IJavaScriptPartitions.JAVA_STRING);
			assistant.setContentAssistProcessor(stringProcessor, IJavaScriptPartitions.JAVA_CHARACTER);

			ContentAssistProcessor multiLineProcessor = new TypeScriptCompletionProcessor(getEditor(), assistant,
					IJavaScriptPartitions.JAVA_MULTI_LINE_COMMENT);
			assistant.setContentAssistProcessor(multiLineProcessor, IJavaScriptPartitions.JAVA_MULTI_LINE_COMMENT);

			ContentAssistProcessor templateLiteralProcessor = new TypeScriptCompletionProcessor(getEditor(), assistant,
					IJavaScriptPartitions.JAVASCRIPT_TEMPLATE_LITERAL);
			assistant.setContentAssistProcessor(templateLiteralProcessor,
					IJavaScriptPartitions.JAVASCRIPT_TEMPLATE_LITERAL);

			ContentAssistProcessor jsxProcessor = new TypeScriptCompletionProcessor(getEditor(), assistant,
					IJSXPartitions.JSX);
			assistant.setContentAssistProcessor(jsxProcessor, IJSXPartitions.JSX);

			ContentAssistProcessor javadocProcessor = new TypeScriptJavadocCompletionProcessor(getEditor(), assistant);
			assistant.setContentAssistProcessor(javadocProcessor, IJavaScriptPartitions.JAVA_DOC);

			ContentAssistPreference.configure(assistant, fPreferenceStore);

			assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
			assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));

//			assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
//			assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_REMOVE);
//			assistant.setAutoActivationDelay(0);
//			assistant.enableColoredLabels(true);
//			assistant.enableAutoActivation(true);
			
			return assistant;
		}
		return null;
	}