org.eclipse.jface.text.IDocumentExtension3 Java Examples

The following examples show how to use org.eclipse.jface.text.IDocumentExtension3. 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: QuickTypeHierarchyHandler.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void openPresentation(final XtextEditor editor, final IJavaElement javaElement,
		final EObject selectedElement) {
	final ISourceViewer sourceViewer = editor.getInternalSourceViewer();
	ITextRegion significantTextRegion = locationInFileProvider.getSignificantTextRegion(selectedElement);
	InformationPresenter presenter = new HierarchyInformationPresenter(sourceViewer, javaElement, new Region(significantTextRegion.getOffset(),significantTextRegion.getLength()));
	presenter.setDocumentPartitioning(IDocumentExtension3.DEFAULT_PARTITIONING);
	presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL);
	IInformationProvider provider = new JavaElementProvider(editor, false);
	presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_STRING);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_CHARACTER);
	presenter.setSizeConstraints(50, 20, true, false);
	presenter.install(sourceViewer);
	presenter.showInformation();
}
 
Example #2
Source File: AbstractDocumentScanner.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected AbstractDocumentScanner(IDocument document, String partitioning, String contentType) {
	this.document = assertNotNull(document);
	this.partitioning = partitioning;
	
	this.source = document.get();
	
	if(partitioning == null) {
		this.contentType = IDocument.DEFAULT_CONTENT_TYPE;
		this.documentExt3 = null;
		this.partitioner = null;
	} else {
		Assert.isLegal(partitioning != null);
		Assert.isLegal(contentType != null);
		this.contentType = contentType;
		
		this.documentExt3 = tryCast(document, IDocumentExtension3.class);
		Assert.isLegal(documentExt3 != null, "document must support IDocumentExtension3");
		this.partitioner = documentExt3.getDocumentPartitioner(partitioning);
		Assert.isLegal(partitioner != null, "document must have a partitioner for " + partitioning);
	}
}
 
Example #3
Source File: PyPartitionScanner.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see http://help.eclipse.org/help31/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_documents.htm
 * @see http://jroller.com/page/bobfoster -  Saturday July 16, 2005
 * @param document the document where we want to add the partitioner
 * @return the added document partitioner (or null)
 */
public static IDocumentPartitioner addPartitionScanner(IDocument document,
        IGrammarVersionProvider grammarVersionProvider) {
    if (document != null) {
        IDocumentExtension3 docExtension = (IDocumentExtension3) document;
        IDocumentPartitioner curr = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE);

        if (curr == null) {
            //set the new one
            PyPartitioner partitioner = createPyPartitioner();
            partitioner.connect(document);
            docExtension.setDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE, partitioner);
            return partitioner;
        } else {
            return curr;
        }
    }
    return null;
}
 
Example #4
Source File: PyPartitionScanner.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks if the partitioner is correctly set in the document.
 * @return the partitioner that is set in the document
 */
public static IDocumentPartitioner checkPartitionScanner(IDocument document,
        IGrammarVersionProvider grammarVersionProvider) {
    if (document == null) {
        return null;
    }

    IDocumentExtension3 docExtension = (IDocumentExtension3) document;
    IDocumentPartitioner partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE);
    if (partitioner == null) {
        addPartitionScanner(document, grammarVersionProvider);
        //get it again for the next check
        partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE);
    }
    if (!(partitioner instanceof PyPartitioner)) {
        Log.log("Partitioner should be subclass of PyPartitioner. It is " + partitioner.getClass());
    }

    return partitioner;
}
 
Example #5
Source File: DocUtils.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static String[] getAllDocumentContentTypes(IDocument document) throws BadPartitioningException {
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 ext = (IDocumentExtension3) document;
        String[] partitionings = ext.getPartitionings();

        Set contentTypes = new HashSet();
        contentTypes.add(IDocument.DEFAULT_CONTENT_TYPE);

        int len = partitionings.length;
        for (int i = 0; i < len; i++) {
            String[] legalContentTypes = ext.getLegalContentTypes(partitionings[i]);
            int len2 = legalContentTypes.length;
            for (int j = 0; j < len2; j++) {
                contentTypes.add(legalContentTypes[j]);
            }
            contentTypes.addAll(Arrays.asList(legalContentTypes));
        }
        return (String[]) contentTypes.toArray(new String[contentTypes.size()]);
    }
    return document.getLegalContentTypes();
}
 
Example #6
Source File: SectionScanner.java    From editorconfig-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isWordStart(char c) {
	if ('=' != c && ':' != c || fDocument == null)
		return false;

	try {
		// check whether it is the first '=' in the logical line

		int i = fOffset - 2;
		while (Character.isWhitespace(fDocument.getChar(i))) {
			i--;
		}

		ITypedRegion partition = null;
		if (fDocument instanceof IDocumentExtension3)
			partition = ((IDocumentExtension3) fDocument)
					.getPartition(IEditorConfigPartitions.EDITOR_CONFIG_PARTITIONING, i, false);
		return partition != null && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType());
	} catch (BadLocationException ex) {
		return false;
	} catch (BadPartitioningException e) {
		return false;
	}
}
 
Example #7
Source File: PropertyValueScanner.java    From editorconfig-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isWordStart(char c) {
	if ('=' != c && ':' != c || fDocument == null)
		return false;

	try {
		// check whether it is the first '=' in the logical line

		int i = fOffset - 2;
		while (Character.isWhitespace(fDocument.getChar(i))) {
			i--;
		}

		ITypedRegion partition = null;
		if (fDocument instanceof IDocumentExtension3)
			partition = ((IDocumentExtension3) fDocument)
					.getPartition(IEditorConfigPartitions.EDITOR_CONFIG_PARTITIONING, i, false);
		return partition != null && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType());
	} catch (BadLocationException ex) {
		return false;
	} catch (BadPartitioningException e) {
		return false;
	}
}
 
Example #8
Source File: AddBlockCommentAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadLocationException, BadPartitioningException {
	int selectionOffset= selection.getOffset();
	int selectionEndOffset= selectionOffset + selection.getLength();
	List<Edit> edits= new LinkedList<Edit>();
	ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, selectionOffset, false);

	handleFirstPartition(partition, edits, factory, selectionOffset);

	while (partition.getOffset() + partition.getLength() < selectionEndOffset) {
		partition= handleInteriorPartition(partition, edits, factory, docExtension);
	}

	handleLastPartition(partition, edits, factory, selectionEndOffset);

	executeEdits(edits);
}
 
Example #9
Source File: PropertyValueScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isWordStart(char c) {
	if ('=' != c && ':' != c || fDocument == null)
		return false;

	try {
		// check whether it is the first '=' in the logical line

		int i=fOffset-2;
		while (Character.isWhitespace(fDocument.getChar(i))) {
			i--;
		}
		
		ITypedRegion partition= null;
		if (fDocument instanceof IDocumentExtension3)
			partition= ((IDocumentExtension3)fDocument).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, i, false);
		return partition != null && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType());
	} catch (BadLocationException ex) {
		return false;
	} catch (BadPartitioningException e) {
		return false;
	}
}
 
Example #10
Source File: PartitionUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets document's partitioner. 
 *
 * @param document the document to be processed
 * @param partitioningType the partitioning for which to set the partitioner
 * @param partitioner the document's new partitioner
 * 
 * @see org.eclipse.jface.text.IDocumentExtension3#setDocumentPartitioner(IDocument,String,IDocumentPartitioner)
 * @see IDocumentPartitioningListener
 */
public static void setDocumentPartitioning( IDocument document
                                          , String partitioningType
                                          , IDocumentPartitioner partitioner ) 
{
    // Setting the partitioner will trigger a partitionChanged listener that
    // will attempt to use the partitioner to initialize the document's
    // partitions. Therefore, need to connect first.
    partitioner.connect(document);
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 extension3= (IDocumentExtension3) document;
        extension3.setDocumentPartitioner(partitioningType, partitioner);
    } else {
        document.setDocumentPartitioner(partitioner);
    }
}
 
Example #11
Source File: DocumentProvider.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected IDocument createDocument(Object element) throws CoreException {
	
	IDocument document = super.createDocument(element);
	//IDocumentPartitioner partitioner = createDocumentPartitioner();
	IDocumentPartitioner partitioner = new ImpexDocumentPartitioner();
	
	if ((document instanceof IDocumentExtension3)) {
		IDocumentExtension3 extension3 = (IDocumentExtension3) document;
		extension3.setDocumentPartitioner(Activator.IMPEX_PARTITIONING, partitioner);
	}
	else {
		document.setDocumentPartitioner(partitioner);
	}
	
	partitioner.connect(document);
	return document;
}
 
Example #12
Source File: JvmImplementationOpener.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void openQuickHierarchy(ITextViewer textViewer, IJavaElement element, IRegion region) {
	HierarchyInformationPresenter presenter = new HierarchyInformationPresenter((ISourceViewer) textViewer,
			element, region);
	presenter.setDocumentPartitioning(IDocumentExtension3.DEFAULT_PARTITIONING);
	presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL);
	IInformationProvider provider = new JavaElementProvider(null, false);
	presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_STRING);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_CHARACTER);
	presenter.setSizeConstraints(50, 20, true, false);
	presenter.install(textViewer);
	presenter.showInformation();
}
 
Example #13
Source File: ImportsAwareClipboardAction.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Should not add imports when pasting into a {@link XStringLiteral} or Comments (except of JavaDoc)
 * 
 * @param document
 *            - {@link IDocument} to work with
 * @param caretOffset
 *            - current caret offset
 */
protected boolean shouldAddImports(IDocument document, int caretOffset) {
	if (caretOffset == 0) {
		return true;
	}
	String typeRight = IDocument.DEFAULT_CONTENT_TYPE;
	String typeLeft = IDocument.DEFAULT_CONTENT_TYPE;
	try {
		typeRight = TextUtilities.getContentType(document, IDocumentExtension3.DEFAULT_PARTITIONING, caretOffset,
				false);
		typeLeft = TextUtilities.getContentType(document, IDocumentExtension3.DEFAULT_PARTITIONING,
				caretOffset > 0 ? caretOffset - 1 : caretOffset, false);
	} catch (BadLocationException exception) {
		// Should not happen
	}
	if (COMMENT_PARTITION.equals(typeRight) || STRING_LITERAL_PARTITION.equals(typeRight)
			|| SL_COMMENT_PARTITION.equals(typeRight) || "__rich_string".equals(typeRight)) {
		if (typeLeft.equals(typeRight))
			return false;
	}
	return true;
}
 
Example #14
Source File: JavaTextTools.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets up the Java document partitioner for the given document for the given partitioning.
 *
 * @param document the document to be set up
 * @param partitioning the document partitioning
 * @since 3.0
 */
public void setupJavaDocumentPartitioner(IDocument document, String partitioning) {
	IDocumentPartitioner partitioner= createDocumentPartitioner();
	if (document instanceof IDocumentExtension3) {
		IDocumentExtension3 extension3= (IDocumentExtension3) document;
		extension3.setDocumentPartitioner(partitioning, partitioner);
	} else {
		document.setDocumentPartitioner(partitioner);
	}
	partitioner.connect(document);
}
 
Example #15
Source File: TexDocumentSetupParticipant.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
public void setup(IDocument document) {
	if (document instanceof IDocumentExtension3) {
		IDocumentExtension3 extension3= (IDocumentExtension3) document;

		IDocumentPartitioner partitioner = 
		    new FastPartitioner(
		            new FastLaTeXPartitionScanner(), 
		            FastLaTeXPartitionScanner.TEX_PARTITION_TYPES);

		extension3.setDocumentPartitioner(TexEditor.TEX_PARTITIONING, partitioner);
        
		partitioner.connect(document);
		
	}	
}
 
Example #16
Source File: EditorConfigDocumentSetupParticipant.java    From editorconfig-eclipse with Apache License 2.0 5 votes vote down vote up
public static void setupDocument(IDocument document) {
	IDocumentPartitioner partitioner = createDocumentPartitioner();
	if (document instanceof IDocumentExtension3) {
		IDocumentExtension3 extension3 = (IDocumentExtension3) document;
		extension3.setDocumentPartitioner(IEditorConfigPartitions.EDITOR_CONFIG_PARTITIONING, partitioner);
	} else {
		document.setDocumentPartitioner(partitioner);
	}
	partitioner.connect(document);
}
 
Example #17
Source File: TexAutoIndentStrategy.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
    if (this.indent) {
        if (itemSetted && autoItem && command.length == 0 && command.text != null
                && TextUtilities.endsWith(document.getLegalLineDelimiters(), command.text) != -1) {
            dropItem(document, command);
        } else if (command.length == 0 && command.text != null
                &&  TextUtilities.endsWith(document.getLegalLineDelimiters(), command.text) != -1) {
            smartIndentAfterNewLine(document, command);
        } else if ("}".equals(command.text)) {
            smartIndentAfterBrace(document, command);
        } else {
            itemSetted = false;
        }
    }

    if (TexAutoIndentStrategy.hardWrap && command.length == 0 && command.text != null) {
        try {
            final String contentType = ((IDocumentExtension3) document).getContentType(
                    TexEditor.TEX_PARTITIONING, command.offset, true);
            // Do not wrap in verbatim partitions
            if (!FastLaTeXPartitionScanner.TEX_VERBATIM.equals(contentType)) {
                hlw.doWrapB(document, command, lineLength);
            }
        }
        catch (Exception e) {
            // If we cannot retrieve the current content type, do not break lines
        }
    }
}
 
Example #18
Source File: RemoveBlockCommentAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
	List<Edit> edits= new LinkedList<Edit>();
	int tokenLength= getCommentStart().length();

	int offset= selection.getOffset();
	int endOffset= offset + selection.getLength();

	ITypedRegion partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, offset, false);
	int partOffset= partition.getOffset();
	int partEndOffset= partOffset + partition.getLength();

	while (partEndOffset < endOffset) {

		if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
			edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
			edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
		}

		partition= docExtension.getPartition(IJavaPartitions.JAVA_PARTITIONING, partEndOffset, false);
		partOffset= partition.getOffset();
		partEndOffset= partOffset + partition.getLength();
	}

	if (partition.getType() == IJavaPartitions.JAVA_MULTI_LINE_COMMENT) {
		edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
		edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
	}

	executeEdits(edits);
}
 
Example #19
Source File: ScriptDebugHover.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion )
{
	ScriptStackFrame frame = getFrame( );
	if ( frame == null )
	{
		return null;
	}
	IDocument document = textViewer.getDocument( );
	if ( document == null )
	{
		return null;
	}
	try
	{
		String str = TextUtilities.getContentType(document, IDocumentExtension3.DEFAULT_PARTITIONING, hoverRegion.getOffset( )+1, true);
		
		String variableName = document.get( hoverRegion.getOffset( ),
				hoverRegion.getLength( ) );
		
		if (JSPartitionScanner.JS_KEYWORD.equals( str ) && !"this".equals( variableName )) //$NON-NLS-1$
		{
			return null;
		}
		ScriptValue var = ( (ScriptDebugTarget) frame.getDebugTarget( ) ).evaluate( frame,
				variableName );
		if ( var != null )
		{
			return getVariableText( var );
		}
	}
	catch ( BadLocationException e )
	{
		return null;
	}
	return null;
}
 
Example #20
Source File: BibSetupParticipant.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
public void setup(IDocument document) {
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 extension3 = (IDocumentExtension3) document;
        IDocumentPartitioner partitioner = 
            new FastPartitioner(new BibPartitionScanner(), BibPartitionScanner.BIB_PARTITION_TYPES);
        extension3.setDocumentPartitioner(BibEditor.BIB_PARTITIONING, partitioner);
        partitioner.connect(document);
    }
}
 
Example #21
Source File: PropertiesFileDocumentSetupParticipant.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param document the document
 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
 */
public static void setupDocument(IDocument document) {
	IDocumentPartitioner partitioner= createDocumentPartitioner();
	if (document instanceof IDocumentExtension3) {
		IDocumentExtension3 extension3= (IDocumentExtension3) document;
		extension3.setDocumentPartitioner(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, partitioner);
	} else {
		document.setDocumentPartitioner(partitioner);
	}
	partitioner.connect(document);
}
 
Example #22
Source File: PartitionUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the partitioner for the given partitioning or <code>null</code> if
 * no partitioner is registered.
 *
 * @param document the document to be processed
 * @param  partitioningType the partitioning for which to set the partitioner
 * @return the partitioner for the given partitioning
 * 
 * @see org.eclipse.jface.text.IDocumentExtension3#getDocumentPartitioner(IDocument,String)
 */
public static IDocumentPartitioner getPartitioner( IDocument document
                                                 , String partitioningType ) 
{
    IDocumentPartitioner result = null;
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 extension = (IDocumentExtension3) document;
        result = extension.getDocumentPartitioner(partitioningType);
    } else if (document != null){
        result = document.getDocumentPartitioner();
    }
    return result;
}
 
Example #23
Source File: ParsingUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param document the document we want to get info on
 * @param i the document offset we're interested in
 * @return the content type at that position (according to IPythonPartitions)
 *
 * Uses the default if the partitioner is not set in the document (for testing purposes)
 */
public static String getContentType(IDocument document, int i) {
    IDocumentExtension3 docExtension = (IDocumentExtension3) document;
    IDocumentPartitionerExtension2 partitioner = (IDocumentPartitionerExtension2) docExtension
            .getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE);

    if (partitioner != null) {
        return partitioner.getContentType(i, true);
    }
    return getContentType(document.get(), i);
}
 
Example #24
Source File: LangDocumentPartitionerSetup.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public void setupPartitioningIfNotSet(IDocument document) {
	if(document instanceof IDocumentExtension3) {
		IDocumentExtension3 extension3 = (IDocumentExtension3) document;
		
		String partitioning = TextSettings_Actual.PARTITIONING_ID;
		
		if(extension3.getDocumentPartitioner(partitioning) == null) {
			IDocumentPartitioner partitioner = createDocumentPartitioner();
			partitioner.connect(document);
			extension3.setDocumentPartitioner(partitioning, partitioner);
		}
	}
}
 
Example #25
Source File: CharacterPairMatcher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private boolean isUnclosedPair(char c, IDocument document, int offset) throws BadLocationException
{
	// TODO Refactor and combine this copy-pasted code from PeerCharacterCloser
	int beginning = 0;
	// Don't check from very beginning of the document! Be smarter/quicker and check from beginning of
	// partition if we can
	if (document instanceof IDocumentExtension3)
	{
		try
		{
			IDocumentExtension3 ext = (IDocumentExtension3) document;
			ITypedRegion region = ext.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, offset, false);
			beginning = region.getOffset();
		}
		catch (BadPartitioningException e)
		{
			// ignore
		}
	}
	// Now check leading source and see if we're an unclosed pair.
	String previous = document.get(beginning, offset - beginning);
	boolean open = false;
	int index = -1;
	while ((index = previous.indexOf(c, index + 1)) != -1)
	{
		open = !open;
	}
	return open;
}
 
Example #26
Source File: EclipseUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static void setupDocumentPartitioner(IDocument document, String partitioning, 
		IDocumentPartitioner partitioner) {
	assertNotNull(document);
	assertNotNull(partitioning);
	assertNotNull(partitioner);
	
	partitioner.connect(document);
	if (document instanceof IDocumentExtension3) {
		IDocumentExtension3 extension3 = (IDocumentExtension3) document;
		extension3.setDocumentPartitioner(partitioning, partitioner);
	} else {
		document.setDocumentPartitioner(partitioner);
	}
}
 
Example #27
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 #28
Source File: StructuredDocumentCloner.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public IStructuredDocument clone(IDocument original) {
  IModelManager modelManager = StructuredModelManager.getModelManager();
  String modelId = getModelId(original);
  if (modelId == null) {
    GWTPluginLog.logError("Could not get a model ID for the document to be formatted.");
    return null;
  }

  /*
   * The XML formatter requires a managed model (discovered by it crashing
   * when given an unmanaged model.) Unfortunately, we cannot create a managed
   * in-memory (i.e. non-file backed) model via IModelManager API (there is
   * one method that may work, but it is deprecated.) Instead, we copy the
   * existing model into a temp model with ID "temp".
   */
  try {
    IStructuredModel modelClone = modelManager.copyModelForEdit(modelId,
        "structuredDocumentClonerModel" + nextId.getAndIncrement());
    modelClone.setBaseLocation(getModelBaseLocation(original));

    IStructuredDocument documentClone = modelClone.getStructuredDocument();
    documentClone.set(original.get());

    // Create and connect the partitioner to the document
    IDocumentPartitioner tempPartitioner = documentPartitionerFactory.createDocumentPartitioner();
    ((IDocumentExtension3) documentClone).setDocumentPartitioner(
        partitioning, tempPartitioner);
    tempPartitioner.connect(documentClone);

    // Save the cloned model so we can release it later
    modelClones.put(documentClone, modelClone);

    return documentClone;
  } catch (ResourceInUse e1) {
    GWTPluginLog.logError(e1,
        "Could not copy the original model to be formatted.");
    return null;
  }
}
 
Example #29
Source File: TLADocumentSetupParticipant.java    From tlaplus with MIT License 5 votes vote down vote up
public void setup(IDocument document) {
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 extension3= (IDocumentExtension3) document;
        IDocumentPartitioner partitioner= new TLAFastPartitioner(TLAEditorActivator.getDefault().getTLAPartitionScanner(), TLAPartitionScanner.TLA_PARTITION_TYPES);
                                            // Changed from FastPartitioner by LL on 12 Aug 2012
        extension3.setDocumentPartitioner(TLAPartitionScanner.TLA_PARTITIONING, partitioner);
        partitioner.connect(document);
    }
}
 
Example #30
Source File: LangAutoEditStrategy.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
protected LangAutoEditStrategy(ILastKeyInfoProvider lastKeyInfoProvider,
	ILangAutoEditsPreferencesAccess preferences) {
	this(lastKeyInfoProvider, IDocumentExtension3.DEFAULT_PARTITIONING, IDocument.DEFAULT_CONTENT_TYPE,
		preferences);
}