Java Code Examples for org.eclipse.jface.text.IDocument#DEFAULT_CONTENT_TYPE

The following examples show how to use org.eclipse.jface.text.IDocument#DEFAULT_CONTENT_TYPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContentAssistant.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: TypeScriptAutoIndentStrategy.java    From typescript.java with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: ConstraintExpressionSourceViewerConfiguration.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: HConfiguration.java    From http4e with Apache License 2.0 5 votes vote down vote up
public String[] getConfiguredContentTypes( ISourceViewer sourceViewer){
   return new String[] { 
         IDocument.DEFAULT_CONTENT_TYPE,  
         HPartitionScanner.COMMENT,
         HPartitionScanner.PROPERTY_VALUE,
         /*HPartitionScanner.PROPERTY_KEY,*/ };
}
 
Example 5
Source File: PartitionCodeReaderTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
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());
}
 
Example 6
Source File: EditorConfigSourceViewerConfiguration.java    From editorconfig-eclipse with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: DotTerminalsTokenTypeToPartitionMapper.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 8
Source File: ImpexDocumentPartitioner.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: SQLSourceViewerConfiguration.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String[] getConfiguredContentTypes( ISourceViewer sourceViewer )
{
	return new String[]{
			SQLPartitionScanner.QUOTE_STRING,
			SQLPartitionScanner.COMMENT,
			IDocument.DEFAULT_CONTENT_TYPE };
}
 
Example 10
Source File: PropertiesFilePartitionScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: EditorConfigPartitionScanner.java    From editorconfig-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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;
}
 
Example 13
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@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;
}
 
Example 14
Source File: PartitionCodeReaderTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: JimpleConfiguration.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
	return new String[] {
		IDocument.DEFAULT_CONTENT_TYPE};
}
 
Example 16
Source File: JavaSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
	final MultiPassContentFormatter formatter= new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE);
	formatter.setMasterStrategy(new JavaFormattingStrategy());
	return formatter;
}
 
Example 17
Source File: TextSettings_Actual.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public String getId() {
	if(ordinal() == 0) {
		return IDocument.DEFAULT_CONTENT_TYPE;
	}
	return toString();
}
 
Example 18
Source File: ScriptConsolePartitioner.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ITypedRegion getPartition(int offset) {
    return new TypedRegion(offset, 1, IDocument.DEFAULT_CONTENT_TYPE);
}
 
Example 19
Source File: PartitionCodeReaderTest.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
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);
}
 
Example 20
Source File: TypeScriptSourceViewerConfiguration.java    From typescript.java with MIT License 4 votes vote down vote up
@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;
	}