org.eclipse.jface.text.ITypedRegion Java Examples

The following examples show how to use org.eclipse.jface.text.ITypedRegion. 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: AbstractEditStrategy.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected String getDocumentContent(IDocument document, DocumentCommand command) throws BadLocationException {
	final ITypedRegion partition = document.getPartition(command.offset);
	ITypedRegion[] partitions = document.getDocumentPartitioner().computePartitioning(0, document.getLength());
	Iterable<ITypedRegion> partitionsOfCurrentType = Iterables.filter(Arrays.asList(partitions),
			new Predicate<ITypedRegion>() {
				@Override
				public boolean apply(ITypedRegion input) {
					return input.getType().equals(partition.getType());
				}
			});
	StringBuilder builder = new StringBuilder();
	for (ITypedRegion position : partitionsOfCurrentType) {
		builder.append(document.get(position.getOffset(), position.getLength()));
	}
	return builder.toString();
}
 
Example #2
Source File: AddBlockCommentAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Handle the partition under the start offset of the selection.
 *
 * @param partition the partition under the start of the selection
 * @param edits the list of edits to later execute
 * @param factory the factory for edits
 * @param offset the start of the selection, which must lie inside
 *        <code>partition</code>
 */
private void handleFirstPartition(ITypedRegion partition, List<Edit> edits, Edit.EditFactory factory, int offset) throws BadLocationException {

	int partOffset= partition.getOffset();
	String partType= partition.getType();

	Assert.isTrue(partOffset <= offset, "illegal partition"); //$NON-NLS-1$

	// first partition: mark start of comment
	if (partType == IDocument.DEFAULT_CONTENT_TYPE) {
		// Java code: right where selection starts
		edits.add(factory.createEdit(offset, 0, getCommentStart()));
	} else if (isSpecialPartition(partType)) {
		// special types: include the entire partition
		edits.add(factory.createEdit(partOffset, 0, getCommentStart()));
	}	// javadoc: no mark, will only start after comment

}
 
Example #3
Source File: TagBasedTLCAnalyzer.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Add start of coverage
 * @param start
 */
public void addTagStart(ITypedRegion start)
{
    // Assert.isTrue(inTag() && !inTag() == !hasUserPartitions(),
    // "Found user partitions which have not been removed. This is a bug.");

    ITypedRegion userRegion = getUserRegion();
    if (userRegion != null)
    {
        stack.push(userRegion);
    }
    TLCRegion startRegion = new TLCRegion(start.getOffset(), start.getLength(), start.getType());
    startRegion.setMessageCode(getMessageCode(start, START));
    startRegion.setSeverity(getSeverity(start));
    // add start to stack
    stack.push(startRegion);
}
 
Example #4
Source File: IndependentMultiPassContentFormatter.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void replaceSlavePartitionsWithDummyText() {
  try {
    ITypedRegion[] partitions = TextUtilities.computePartitioning(
        tempDocument, partitioning, 0, tempDocument.getLength(), false);
    for (int i = 0; i < partitions.length; i++) {
      if (!isSlaveContentType(partitions[i].getType())) {
        continue;
      }

      // Ideally, we'd like to use whitespace as the dummy text, but it may
      // cause the partition to be lost by the master formatter. Instead this
      // uses periods.
      tempDocument.replace(partitions[i].getOffset(),
          partitions[i].getLength(), StringUtilities.repeatCharacter('.',
              partitions[i].getLength()));
    }
  } catch (BadLocationException e) {
    // This should not happen according to super class
  }
}
 
Example #5
Source File: JsniFormattingUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static String[] getJsniMethods(IDocument document) {

    try {
      List<String> jsniMethods = new LinkedList<String>();
      ITypedRegion[] regions = TextUtilities.computePartitioning(document,
          GWTPartitions.GWT_PARTITIONING, 0, document.getLength(), false);

      // Format all JSNI blocks in the document
      for (ITypedRegion region : regions) {
        if (region.getType().equals(GWTPartitions.JSNI_METHOD)) {
          String jsni = document.get(region.getOffset(), region.getLength());
          jsniMethods.add(jsni);
        }
      }

      return jsniMethods.toArray(new String[0]);

    } catch (BadLocationException e) {
      GWTPluginLog.logError(e);
      return null;
    }
  }
 
Example #6
Source File: DummyListener.java    From tlaplus with MIT License 6 votes vote down vote up
public void onOutput(ITypedRegion region, String text) {
	// a) just store the region
	this.regions.add(region);

	// b) convert to TLCState if TLCRegion
	if (region instanceof TLCRegion) {
		TLCRegion tlcRegion = (TLCRegion) region;
		int severity = tlcRegion.getSeverity();
		switch (severity) {
		case MP.STATE:
			TLCState state = TLCState.parseState(text, "bogusModelName");
			this.states.add(state);
			return;
		}
	}
	
	// c) unexpected content
	this.garbage  = true;
}
 
Example #7
Source File: TagBasedTLCAnalyzer.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Returns array of elements from top of the stack with start as the last element (call pop until the start is found) 
 * @param code
 * @return
 */
private ITypedRegion[] getFindStart(int code)
{
    Assert.isTrue(!stack.isEmpty(), "Bug. Empty stack, start tag expected");

    Vector<ITypedRegion> elements = new Vector<ITypedRegion>();
    while (!stack.isEmpty())
    {
        ITypedRegion region = (ITypedRegion) stack.pop();
        elements.add(region);
        if (TagBasedTLCOutputTokenScanner.TAG_OPEN.equals(region.getType()))
        {
            TLCRegion startRegion = (TLCRegion) region;
            Assert.isTrue(startRegion.getMessageCode() == code, "Found a non-matching start. This is a bug.");
            // found a match
            break;
        } else
        {
            // not a start tag
            // but something else, e.G. user partition

        }
    }

    return (ITypedRegion[]) elements.toArray(new ITypedRegion[elements.size()]);
}
 
Example #8
Source File: JavaChangeHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the partition type of the document displayed in <code>viewer</code> at <code>startLine</code>.

 * @param viewer the viewer
 * @param startLine the line in the viewer
 * @return the partition type at the start of <code>startLine</code>, or <code>IDocument.DEFAULT_CONTENT_TYPE</code> if none can be detected
 */
private String getPartition(ISourceViewer viewer, int startLine) {
	if (viewer == null)
		return null;
	IDocument doc= viewer.getDocument();
	if (doc == null)
		return null;
	if (startLine <= 0)
		return IDocument.DEFAULT_CONTENT_TYPE;
	try {
		ITypedRegion region= TextUtilities.getPartition(doc, fPartitioning, doc.getLineOffset(startLine) - 1, true);
		return region.getType();
	} catch (BadLocationException e) {
	}
	return IDocument.DEFAULT_CONTENT_TYPE;
}
 
Example #9
Source File: DamageRepairer.java    From LogViewer with Eclipse Public License 2.0 6 votes vote down vote up
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
    int start= region.getOffset();
    int length= 0;
    boolean firstToken= true;
    TextAttribute attribute = getTokenTextAttribute(Token.UNDEFINED);

    scanner.setRange(document,start,region.getLength());

    while (true) {
        IToken resultToken = scanner.nextToken();
        if (resultToken.isEOF()) {
            break;
        }
        if(resultToken.equals(Token.UNDEFINED)) {
        	continue;
        }
        if (!firstToken) {
        	addRange(presentation,start,length,attribute,true);
        }
        firstToken = false;
        attribute = getTokenTextAttribute(resultToken);
        start = scanner.getTokenOffset();
        length = scanner.getTokenLength();
    }
    addRange(presentation,start,length,attribute,true);
}
 
Example #10
Source File: RemoveBlockCommentHandler.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private ITypedRegion searchCommentStart(IDocument doc, int pos, int addLines) throws BadLocationException {
    int lnum = doc.getLineOfOffset(pos);
    lnum += addLines;
    if (lnum < doc.getNumberOfLines()) {
        IRegion reg = doc.getLineInformation(lnum);
        String line = doc.get(reg.getOffset(), reg.getLength());
        for (int i = addLines > 0 ? 0 : pos - reg.getOffset(); i < line.length(); ++i) {
            if (line.charAt(i) == '(' && 
                i+1 < line.length() && 
                line.charAt(i+1) == '*')
            {
                ITypedRegion partition = TextUtilities.getPartition(doc, IModulaPartitions.M2_PARTITIONING, 
                        reg.getOffset() + i, false);
                if (partition.getType().equals(IModulaPartitions.M2_CONTENT_TYPE_BLOCK_COMMENT)) {
                    return partition;
                }
            }
        }
    }
    return null;
}
 
Example #11
Source File: PartitionDoubleClickSelector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IRegion findExtendedDoubleClickSelection(IDocument document, int offset) {
	IRegion match= super.findExtendedDoubleClickSelection(document, offset);
	if (match != null)
		return match;

	try {
		ITypedRegion region= TextUtilities.getPartition(document, fPartitioning, offset, true);
		if (offset == region.getOffset() + fHitDelta || offset == region.getOffset() + region.getLength() - fHitDelta) {
			if (fLeftBorder == 0 && fRightBorder == 0)
				return region;
			if (fRightBorder == -1) {
				String delimiter= document.getLineDelimiter(document.getLineOfOffset(region.getOffset() + region.getLength() - 1));
				if (delimiter == null)
					fRightBorder= 0;
				else
					fRightBorder= delimiter.length();
			}
			return new Region(region.getOffset() + fLeftBorder, region.getLength() - fLeftBorder - fRightBorder);
		}
	} catch (BadLocationException e) {
		return null;
	}
	return null;
}
 
Example #12
Source File: JavaHeuristicScanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int nextPosition(int position, boolean forward) {
	ITypedRegion partition= getPartition(position);
	if (fPartition.equals(partition.getType()))
		return super.nextPosition(position, forward);

	if (forward) {
		int end= partition.getOffset() + partition.getLength();
		if (position < end)
			return end;
	} else {
		int offset= partition.getOffset();
		if (position > offset)
			return offset - 1;
	}
	return super.nextPosition(position, forward);
}
 
Example #13
Source File: AbstractDocumentScanner.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
protected final int readPreviousCharacter() {
	if(pos <= posLimit) {
		return token = TOKEN_EOF;
	} else {
		
		ITypedRegion partition;
		try {
			partition = getPartition(pos-1);
		} catch(BadLocationException e) {
			return token = TOKEN_OUTSIDE;
		}
		
		pos--;
		if (contentType.equals(partition.getType())) {
			return token = source.charAt(pos);
		} else {
			pos = partition.getOffset();
			return token = TOKEN_OUTSIDE;
		}
	}
}
 
Example #14
Source File: DocumentUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * searches backwards for the given string within the same partition type
 * @return the region of the match or <code>null</code> if no match were found
 * @since 2.4
 */
public IRegion searchBackwardsInSamePartition(String toFind, String documentText, IDocument document, int endOffset) throws BadLocationException {
	if (endOffset < 0) {
		return null;
	}
	int length = toFind.length();
	String text = preProcessSearchString(documentText);
	ITypedRegion partition = document.getPartition(endOffset);
	int indexOf = text.lastIndexOf(toFind, endOffset - length);
	while (indexOf >= 0) {
		ITypedRegion partition2 = document.getPartition(indexOf);
		if (partition2.getType().equals(partition.getType())) {
			return new Region(indexOf, length);
		}
		indexOf = text.lastIndexOf(toFind, partition2.getOffset() - length);
	}
	String trimmed = toFind.trim();
	if (trimmed.length() > 0 && trimmed.length() != length) {
		return searchBackwardsInSamePartition(trimmed, documentText, document, endOffset);
	}
	return null;
}
 
Example #15
Source File: JsniParser.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static ITypedRegion getEnclosingJsniRegion(ITextSelection selection,
    IDocument document) {
  try {
    ITypedRegion region = TextUtilities.getPartition(document,
        GWTPartitions.GWT_PARTITIONING, selection.getOffset(), false);

    if (region.getType().equals(GWTPartitions.JSNI_METHOD)) {
      int regionEnd = region.getOffset() + region.getLength();
      int selectionEnd = selection.getOffset() + selection.getLength();

      // JSNI region should entirely contain the selection
      if (region.getOffset() <= selection.getOffset()
          && regionEnd >= selectionEnd) {
        return region;
      }
    }
  } catch (BadLocationException e) {
    GWTPluginLog.logError(e);
  }

  return null;
}
 
Example #16
Source File: DocumentPartitioner.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * May be replaced or extended by subclasses.
 * </p>
 * 
 * @since 2.2
 */
@Override
public synchronized ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
	ITypedRegion region = getPartition(offset);
	if (preferOpenPartitions) {
		if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
			if (offset > 0) {
				region = getPartition(offset - 1);
				if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE))
					return region;
			}
			return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE);
		}
	}
	return region;
}
 
Example #17
Source File: UiBinderStructuredRegionProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean isInterestingProblem(SpellingProblem problem) {
  IStructuredDocument doc = (IStructuredDocument) getDocument();
  try {
    ITypedRegion[] partitions = doc.computePartitioning(
        problem.getOffset(), problem.getLength());
    for (ITypedRegion partition : partitions) {
      if (partition.getType().equals(ICSSPartitions.STYLE)) {
        return false;
      }
    }
  } catch (BadLocationException e) {
    // Ignore
  }

  return super.isInterestingProblem(problem);
}
 
Example #18
Source File: PartitionTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testJavaDoc_ML_COMMENTPartitions() throws BadLocationException {
	String input = "/* some comment */class Foo {}";
	document.set(input);
	ITypedRegion[] partitions = document.getDocumentPartitioner().computePartitioning(0, input.length());
	assertEquals(2, partitions.length);
	assertEquals("__comment", partitions[0].getType());
	document.replace(input.indexOf("/* some comment */"), "/* some comment */".length(), "/** some comment */");
	partitions = document.getDocumentPartitioner().computePartitioning(0, input.length() + 1/* * */);
	assertEquals(2, partitions.length);
	assertEquals("__java_javadoc", partitions[0].getType());
	document.replace(input.indexOf("/* some comment */"), "/** some comment */".length(), "/*** some comment */");
	partitions = document.getDocumentPartitioner().computePartitioning(0, input.length() + 2/* ** */);
	assertEquals(2, partitions.length);
	assertEquals("__comment", partitions[0].getType());

}
 
Example #19
Source File: TagBasedTLCAnalyzer.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * @return
 */
public ITypedRegion getUserRegion()
{
    if (hasUserPartitions())
    {
        ITypedRegion region = PartitionToolkit.mergePartitions((ITypedRegion[]) userOutput
                .toArray(new TypedRegion[userOutput.size()]));
        // re-initialize the user partitions
        resetUserPartitions();
        return region;
    } else
    {
        return null;
    }
}
 
Example #20
Source File: TagBasedTLCAnalyzer.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Add the end of coverage
 * @param end
 */
public void addTagEnd(ITypedRegion end)
{
    ITypedRegion userRegion = getUserRegion();
    if (userRegion != null)
    {
        stack.push(userRegion);
    }
    processTag(end);
    
}
 
Example #21
Source File: HackDefaultCharacterPairMatcher.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns partition information about the region containing the
 * specified position.
 * 
 * @param pos a position within this document.
 * @return positioning information about the region containing the
 *   position
 */
private ITypedRegion getPartition(int pos) {
	if (fCachedPartition == null || !contains(fCachedPartition, pos)) {
		Assert.isTrue(pos >= 0 && pos <= fDocument.getLength());
		try {
			fCachedPartition= TextUtilities.getPartition(fDocument, fPartitioning, pos, false);
		} catch (BadLocationException e) {
			fCachedPartition= null;
		}
	}
	return fCachedPartition;
}
 
Example #22
Source File: PartitionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testPartitioningAfterModify_01() throws BadLocationException {
	String input = "class SomeType {\n" + 
			"	def someOperation() '''\n" + 
			"		Dear,\n" + 
			"		bla bla foo\n" + 
			"		\n" + 
			"		Yours sincerely,\n" + 
			"		\n" + 
			"		Joe Developer\n" + 
			"		\n" + 
			"	'''	\n" + 
			"}";
	document.set(input);
	document.replace(input.indexOf("\t\tYours"), 0, "���");
	ITypedRegion[] partitions = document.getDocumentPartitioner().computePartitioning(0, input.length()  + 3 /*���*/);
	assertEquals(4, partitions.length);
	ITypedRegion first = partitions[0];
	assertEquals(0, first.getOffset());
	assertEquals(input.indexOf("'"), first.getLength());
	assertEquals(IDocument.DEFAULT_CONTENT_TYPE, first.getType());
	ITypedRegion second = partitions[1];
	assertEquals(input.indexOf("'"), second.getOffset());
	assertEquals(input.indexOf("\t\tYours") + 1, second.getLength() + second.getOffset());
	assertEquals(TokenTypeToPartitionMapper.RICH_STRING_LITERAL_PARTITION, second.getType());
	ITypedRegion third = partitions[2];
	assertEquals(input.indexOf("\t\tYours") + 1, third.getOffset());
	assertEquals(input.lastIndexOf("'") + 1 + 3 /*���*/, third.getLength() + third.getOffset());
	assertEquals(TokenTypeToPartitionMapper.RICH_STRING_LITERAL_PARTITION, third.getType());
	ITypedRegion forth = partitions[3];
	assertEquals(input.lastIndexOf("'") + 1 + 3 /*���*/, forth.getOffset());
	assertEquals(input.length() + 3 /*���*/, forth.getLength() + forth.getOffset());
	assertEquals(IDocument.DEFAULT_CONTENT_TYPE, forth.getType());
}
 
Example #23
Source File: XMLContentAssistProcessor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * getUnclosedTagNames
 * 
 * @param offset
 * @return
 */
protected Set<String> getUnclosedTagNames(int offset)
{
	Set<String> unclosedElements = new HashSet<String>();

	try
	{
		ITypedRegion[] partitions = _document.computePartitioning(0, offset);

		for (ITypedRegion partition : partitions)
		{
			if (partition.getType().equals(XMLSourceConfiguration.TAG))
			{
				String src = _document.get(partition.getOffset(), partition.getLength());
				int lessThanIndex = src.indexOf('<');

				if (lessThanIndex == -1 || lessThanIndex >= src.length() - 1)
				{
					continue;
				}

				src = src.substring(lessThanIndex + 1).trim();

				String[] parts = src.split("\\W"); //$NON-NLS-1$

				if (parts == null || parts.length == 0)
				{
					continue;
				}
			}
		}
	}
	catch (BadLocationException e)
	{
		// ignore
	}

	return unclosedElements;
}
 
Example #24
Source File: MultiRegionSpellingReconcileStrategy.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Computes and returns the partitioning for the given region of the input document
 * of the reconciler's connected text viewer.
 *
 * @param offset the region offset
 * @param length the region length
 * @return the computed partitioning
 * @since 3.0
 */
private ITypedRegion[] computePartitioning(int offset, int length)
{
	ITypedRegion[] regions = null;
	try
	{
		regions = TextUtilities.computePartitioning(getDocument(), getDocumentPartitioning(), offset, length, false);
	} catch (BadLocationException x)
	{
		regions = new TypedRegion[0];
	}
	return regions;
}
 
Example #25
Source File: XtextSpellingReconcileStrategy.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void reconcile(IRegion region) {
	if (!isSpellingEnabled()) {
		return;
	}
	ITypedRegion[] regions = computePartitioning(0, getDocument().getLength(), DEFAULT_PARTITIONING);
	spellingService.check(getDocument(), regions, spellingContext, spellingProblemCollector, progressMonitor);
}
 
Example #26
Source File: MultiLineTerminalsEditStrategy.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * determines the offset of the next ITypedRegion of type {@link IDocument#DEFAULT_CONTENT_TYPE} starting from the given offset  
 * Fix for bug 403812.  
 */
private int findOffsetOfNextDftlContentPartition(IDocument document, int startOffset) throws BadLocationException{
	if (startOffset >= document.getLength()) {
		return startOffset;
	}
	ITypedRegion partition = document.getPartition(startOffset);
	if(IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())){
		return startOffset;
	}else{
		return findOffsetOfNextDftlContentPartition(document,partition.getOffset()+partition.getLength());
	}
}
 
Example #27
Source File: JsniFormattingUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a text edit that formats the given document according to the given
 * settings.
 * 
 * @param document The document to format.
 * @param javaFormattingPrefs The formatting preferences for Java, used to
 *          determine the method level indentation.
 * @param javaScriptFormattingPrefs The formatting preferences for JavaScript.
 *          See org.eclipse.wst.jsdt.internal.formatter
 *          .DefaultCodeFormatterOptions and
 *          org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants
 * @param originalJsniMethods The original jsni methods to use if the
 *          formatter fails to format the method. The original jsni Strings
 *          must be in the same order that the jsni methods occur in the
 *          document. This is to work around the Java formatter blasting the
 *          jsni tabbing for the format-on-save action. May be null.
 * @return A text edit that when applied to the document, will format the jsni
 *         methods.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public static TextEdit format(IDocument document, Map javaFormattingPrefs,
    Map javaScriptFormattingPrefs, String[] originalJsniMethods) {
  TextEdit combinedEdit = new MultiTextEdit();
  try {
    ITypedRegion[] regions = TextUtilities.computePartitioning(document,
        GWTPartitions.GWT_PARTITIONING, 0, document.getLength(), false);

    // Format all JSNI blocks in the document
    int i = 0;
    for (ITypedRegion region : regions) {
      if (region.getType().equals(GWTPartitions.JSNI_METHOD)) {
        String originalJsniMethod = null;
        if (originalJsniMethods != null && i < originalJsniMethods.length) {
          originalJsniMethod = originalJsniMethods[i];
        }
        TextEdit edit = format(document, new TypedPosition(region),
            javaFormattingPrefs, javaScriptFormattingPrefs,
            originalJsniMethod);
        if (edit != null) {
          combinedEdit.addChild(edit);
        }
        i++;
      }
    }
    return combinedEdit;

  } catch (BadLocationException e) {
    GWTPluginLog.logError(e);
    return null;
  }
}
 
Example #28
Source File: PresentationRepairer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
	if (fScanner == null) {
		// will be removed if deprecated constructor will be removed
		addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle);
		return;
	}

	int lastStart = region.getOffset();
	int length = 0;
	boolean firstToken = true;
	IToken lastToken = Token.UNDEFINED;
	TextStyle lastTextStyle = getTokenTextStyle(lastToken);

	fScanner.setRange(fDocument, lastStart, region.getLength());

	while (true) {
		IToken token = fScanner.nextToken();
		if (token.isEOF())
			break;

		TextStyle textStyle = getTokenTextStyle(token);
		if (lastTextStyle != null && lastTextStyle.equals(textStyle)) {
			length += fScanner.getTokenLength();
			firstToken = false;
		} else {
			if (!firstToken)
				addRange(presentation, lastStart, length, lastTextStyle);
			firstToken = false;
			lastToken = token;
			lastTextStyle = textStyle;
			lastStart = fScanner.getTokenOffset();
			length = fScanner.getTokenLength();
		}
	}

	addRange(presentation, lastStart, length, lastTextStyle);
}
 
Example #29
Source File: NonRuleBasedDamagerRepairer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected TextAttribute getTextAttribute(ITypedRegion region)
{
	Object data = fDefaultTextAttribute.getData();
	if (data instanceof String)
	{
		// Cache the full scope so we can just re-use it. It shouldn't ever change... Previous caching of text
		// attribute ended up breaking when theme changed
		if (fFullScope == null)
		{
			try
			{
				String last = (String) data;
				int offset = region.getOffset();
				String scope = getDocumentScopeManager().getScopeAtOffset(fDocument, offset);
				if (last.length() == 0)
				{
					last = scope;
				}
				else if (!scope.endsWith(last))
				{
					scope += ' ' + last;
				}
				fFullScope = scope;
			}
			catch (BadLocationException e)
			{
				IdeLog.logError(CommonEditorPlugin.getDefault(), e);
			}
		}
		IToken token = getThemeManager().getToken(fFullScope);
		data = token.getData();
	}
	if (data instanceof TextAttribute)
	{
		return (TextAttribute) data;
	}
	return null;
}
 
Example #30
Source File: TagUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns null when no match found! Assumes the document has been partitioned via HTML partition scanner
 * 
 * @param document
 * @param offset
 * @param partitionsToSearch
 *            A collection of the string partition names to search for tags. Optimization to avoid looking in non
 *            HTML/XML tags!
 * @return
 */
public static IRegion findMatchingTag(IDocument document, int offset, Collection<String> partitionsToSearch)
{
	try
	{
		ITypedRegion region = document.getPartition(offset);
		if (!partitionsToSearch.contains(region.getType()))
		{
			return null;
		}
		String src = document.get(region.getOffset(), region.getLength());
		if (src.startsWith("</")) //$NON-NLS-1$
		{
			return findMatchingOpen(document, region, partitionsToSearch);
		}
		// Handle self-closing tags!
		if (src.endsWith("/>")) //$NON-NLS-1$
		{
			return null;
		}
		return findMatchingClose(document, region, partitionsToSearch);
	}
	catch (BadLocationException e)
	{
		IdeLog.logError(XMLPlugin.getDefault(), e);
	}
	return null;
}