类org.eclipse.jface.text.IDocumentExtension3源码实例Demo

下面列出了怎么用org.eclipse.jface.text.IDocumentExtension3的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xtext-eclipse   文件: QuickTypeHierarchyHandler.java
@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();
}
 
源代码2 项目: xtext-eclipse   文件: JvmImplementationOpener.java
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();
}
 
/**
 * 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;
}
 
@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;
}
 
源代码5 项目: xds-ide   文件: PartitionUtils.java
/**
 * 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);
    }
}
 
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;
	}
}
 
@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);
}
 
@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;
	}
}
 
源代码9 项目: editorconfig-eclipse   文件: SectionScanner.java
@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;
	}
}
 
源代码10 项目: Pydev   文件: DocUtils.java
@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();
}
 
源代码11 项目: Pydev   文件: PyPartitionScanner.java
/**
 * 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;
}
 
源代码12 项目: Pydev   文件: PyPartitionScanner.java
/**
 * @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;
}
 
源代码13 项目: goclipse   文件: AbstractDocumentScanner.java
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);
	}
}
 
源代码14 项目: 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;
}
 
源代码15 项目: texlipse   文件: BibSetupParticipant.java
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);
    }
}
 
源代码16 项目: texlipse   文件: TexDocumentSetupParticipant.java
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);
		
	}	
}
 
源代码17 项目: texlipse   文件: TexAutoIndentStrategy.java
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
        }
    }
}
 
源代码18 项目: xds-ide   文件: PartitionUtils.java
/**
 * 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;
}
 
源代码19 项目: tlaplus   文件: TLADocumentSetupParticipant.java
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);
    }
}
 
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;
  }
}
 
源代码21 项目: APICloud-Studio   文件: CharacterPairMatcher.java
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;
}
 
/**
 * 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);
}
 
/**
 * @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);
}
 
@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);
}
 
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);
}
 
源代码26 项目: birt   文件: ScriptDebugHover.java
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;
}
 
源代码27 项目: Pydev   文件: ParsingUtils.java
/**
 * @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);
}
 
源代码28 项目: goclipse   文件: LangDocumentPartitionerSetup.java
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);
		}
	}
}
 
源代码29 项目: goclipse   文件: EclipseUtils.java
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);
	}
}
 
源代码30 项目: gwt-eclipse-plugin   文件: EditorAction.java
public void run(IAction action) {
  if (targetEditor == null) {
    GWTPluginLog.logWarning("targetEditor is null");
    return;
  }

  IEditorInput editorInput = targetEditor.getEditorInput();
  IResource resource = (IResource) editorInput.getAdapter(IResource.class);
  ITextEditor javaEditor = (ITextEditor) targetEditor;
  ITextSelection sel = (ITextSelection) javaEditor.getSelectionProvider().getSelection();
  IDocument document = javaEditor.getDocumentProvider().getDocument(
      javaEditor.getEditorInput());

  IDocumentExtension3 document3 = (IDocumentExtension3) document;
  IDocumentPartitioner gwtPartitioner = document3.getDocumentPartitioner(GWTPartitions.GWT_PARTITIONING);

  String[] partitionings = document3.getPartitionings();
  String partitioning = (gwtPartitioner != null
      ? GWTPartitions.GWT_PARTITIONING : IJavaPartitions.JAVA_PARTITIONING);

  ITypedRegion[] types;
  try {
    types = TextUtilities.computePartitioning(document, partitioning,
        sel.getOffset(), sel.getLength(), false);
  } catch (BadLocationException e) {
    GWTPluginLog.logError(e);
    return;
  }

  String msg = "File: " + resource.getName();

  msg += "\nPartitionings: ";
  for (String part : partitionings) {
    msg += "\n" + part;
  }

  msg += "\n\nContent types: ";
  for (ITypedRegion type : types) {
    msg += "\n" + type.getType();
  }

  msg += "\n\nSelection range: (offset = " + sel.getOffset() + ", length = "
      + sel.getLength() + ")";

  MessageDialog.openInformation(targetEditor.getSite().getShell(),
      "Selection Info", msg);
}
 
 类所在包
 同包方法