当前位置: 首页>>代码示例>>Java>>正文


Java ITypeRoot.getBuffer方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.ITypeRoot.getBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java ITypeRoot.getBuffer方法的具体用法?Java ITypeRoot.getBuffer怎么用?Java ITypeRoot.getBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.ITypeRoot的用法示例。


在下文中一共展示了ITypeRoot.getBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNodeSource

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * Returns the source of the given node from the location where it was parsed.
 * @param node the node to get the source from
 * @param extendedRange if set, the extended ranges of the nodes should ne used
 * @param removeIndent if set, the indentation is removed.
 * @return return the source for the given node or null if accessing the source failed.
 */
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
	ASTNode root= node.getRoot();
	if (root instanceof CompilationUnit) {
		CompilationUnit astRoot= (CompilationUnit) root;
		ITypeRoot typeRoot= astRoot.getTypeRoot();
		try {
			if (typeRoot != null && typeRoot.getBuffer() != null) {
				IBuffer buffer= typeRoot.getBuffer();
				int offset= extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition();
				int length= extendedRange ? astRoot.getExtendedLength(node) : node.getLength();
				String str= buffer.getText(offset, length);
				if (removeIndent) {
					IJavaProject project= typeRoot.getJavaProject();
					int indent= getIndentUsed(buffer, node.getStartPosition(), project);
					str= Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
				}
				return str;
			}
		} catch (JavaModelException e) {
			// ignore
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:32,代码来源:ASTNodes.java

示例2: getLineNumber

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
public static Integer getLineNumber(IMember member) throws JavaModelException {
	ITypeRoot typeRoot = member.getTypeRoot();
	IBuffer buffer = typeRoot.getBuffer();
	if (buffer == null) {
		return null;
	}
	Document document = new Document(buffer.getContents());

	int offset = 0;
	if (SourceRange.isAvailable(member.getNameRange())) {
		offset = member.getNameRange().getOffset();
	} else if (SourceRange.isAvailable(member.getSourceRange())) {
		offset = member.getSourceRange().getOffset();
	}
	try {
		return document.getLineOfOffset(offset);
	} catch (BadLocationException e) {
		return null;
	}
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:21,代码来源:JavaEditorUtils.java

示例3: TokenScanner

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * Creates a TokenScanner
 *
 * @param typeRoot The type root to scan on
 * @throws CoreException thrown if the buffer cannot be accessed
 */
public TokenScanner(ITypeRoot typeRoot) throws CoreException {
  IJavaProject project = typeRoot.getJavaProject();
  IBuffer buffer = typeRoot.getBuffer();
  if (buffer == null) {
    throw new CoreException(
        createError(DOCUMENT_ERROR, "Element has no source", null)); // $NON-NLS-1$
  }
  String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
  String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
  fScanner =
      ToolFactory.createScanner(
          true, false, true, sourceLevel, complianceLevel); // line info required

  fScanner.setSource(buffer.getCharacters());
  fDocument = null; // use scanner for line information
  fEndPosition = fScanner.getSource().length - 1;
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:TokenScanner.java

示例4: getNodeSource

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * Returns the source of the given node from the location where it was parsed.
 * @param node the node to get the source from
 * @param extendedRange if set, the extended ranges of the nodes should ne used
 * @param removeIndent if set, the indentation is removed.
 * @return return the source for the given node or null if accessing the source failed.
 */
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
	ASTNode root= node.getRoot();
	if (root instanceof CompilationUnit) {
		CompilationUnit astRoot= (CompilationUnit) root;
		ITypeRoot typeRoot= astRoot.getTypeRoot();
		try {
			if (typeRoot != null && typeRoot.getBuffer() != null) {
				IBuffer buffer= typeRoot.getBuffer();
				int offset= extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition();
				int length= extendedRange ? astRoot.getExtendedLength(node) : node.getLength();
				String str= buffer.getText(offset, length);
				if (removeIndent) {
					IJavaProject project= typeRoot.getJavaProject();
					int indent= StubUtility.getIndentUsed(buffer, node.getStartPosition(), project);
					str= Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
				}
				return str;
			}
		} catch (JavaModelException e) {
			// ignore
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:32,代码来源:ASTNodes.java

示例5: hasSource

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * Checks whether the given Java element has accessible source.
 *
 * @param je the Java element to test
 * @return <code>true</code> if the element has source
 */
private static boolean hasSource(ITypeRoot je) {
	if (je == null || !je.exists()) {
		return false;
	}

	try {
		return je.getBuffer() != null;
	} catch (JavaModelException ex) {
		IStatus status= new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, IStatus.OK, "Error in JDT Core during AST creation", ex);  //$NON-NLS-1$
		JavaLanguageServerPlugin.log(status);
	}
	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:SharedASTProvider.java

示例6: TokenScanner

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * Creates a TokenScanner
 * @param typeRoot The type root to scan on
 * @throws CoreException thrown if the buffer cannot be accessed
 */
public TokenScanner(ITypeRoot typeRoot) throws CoreException {
	IJavaProject project= typeRoot.getJavaProject();
	IBuffer buffer= typeRoot.getBuffer();
	if (buffer == null) {
		throw new CoreException(createError(DOCUMENT_ERROR, "Element has no source", null)); //$NON-NLS-1$
	}
	String sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true);
	String complianceLevel= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
	fScanner= ToolFactory.createScanner(true, false, true, sourceLevel, complianceLevel); // line info required

	fScanner.setSource(buffer.getCharacters());
	fDocument= null; // use scanner for line information
	fEndPosition= fScanner.getSource().length - 1;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:TokenScanner.java

示例7: getLineNumber

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
private LinePosition getLineNumber(IMember member, Bookmark bookmark, IProgressMonitor monitor) {
	Integer estimatedLineNumber = getEstimatedLineNumber(member, bookmark);
	Integer lineNumber = estimatedLineNumber;
	Integer lineOffset = null;
	String lineContent = bookmark.getPropertyValue(TextEditorBookmarkProperties.PROP_LINE_CONTENT);
	try {
		ITypeRoot typeRoot = member.getTypeRoot();
		if (typeRoot.getBuffer() == null) {
			return null;
		}
		Document document = new Document(typeRoot.getBuffer().getContents());
		if (lineContent != null) {
			DocumentFuzzySearcher searcher = new DocumentFuzzySearcher(document);

			int foundLineNumber = searcher.findLineNumber(getRegion(member.getSourceRange()),
					estimatedLineNumber == null ? -1 : estimatedLineNumber, lineContent, monitor);
			lineNumber = foundLineNumber == -1 ? estimatedLineNumber : foundLineNumber;
		}
		if (lineNumber == null) {
			return null;
		}
		lineOffset = getLineOffset(document, lineNumber);
		if (lineOffset == null) {
			return null;
		}
		return new LinePosition(lineNumber, lineOffset);
	} catch (JavaModelException e) {
		return null;
	}
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:31,代码来源:JavaTypeMemberBookmarkLocationProvider.java

示例8: getNodeSource

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * Returns the source of the given node from the location where it was parsed.
 *
 * @param node the node to get the source from
 * @param extendedRange if set, the extended ranges of the nodes should ne used
 * @param removeIndent if set, the indentation is removed.
 * @return return the source for the given node or null if accessing the source failed.
 */
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
  ASTNode root = node.getRoot();
  if (root instanceof CompilationUnit) {
    CompilationUnit astRoot = (CompilationUnit) root;
    ITypeRoot typeRoot = astRoot.getTypeRoot();
    try {
      if (typeRoot != null && typeRoot.getBuffer() != null) {
        IBuffer buffer = typeRoot.getBuffer();
        int offset =
            extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition();
        int length = extendedRange ? astRoot.getExtendedLength(node) : node.getLength();
        String str = buffer.getText(offset, length);
        if (removeIndent) {
          IJavaProject project = typeRoot.getJavaProject();
          int indent = StubUtility.getIndentUsed(buffer, node.getStartPosition(), project);
          str =
              Strings.changeIndent(
                  str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
        }
        return str;
      }
    } catch (JavaModelException e) {
      // ignore
    }
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:36,代码来源:ASTNodes.java

示例9: hasSource

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * Checks whether the given Java element has accessible source.
 *
 * @param je the Java element to test
 * @return <code>true</code> if the element has source
 * @since 3.2
 */
private static boolean hasSource(ITypeRoot je) {
  if (je == null || !je.exists()) return false;

  try {
    return je.getBuffer() != null;
  } catch (JavaModelException ex) {
    LOG.error(ex.getMessage(), ex);
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:ASTProvider.java

示例10: perform

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * A visitor that maps a selection to a given ASTNode. The result node is
 * determined as follows:
 * <ul>
 *   <li>first the visitor tries to find a node that is covered by <code>start</code> and
 *       <code>length</code> where either <code>start</code> and <code>length</code> exactly
 *       matches the node or where the text covered before and after the node only consists
 *       of white spaces or comments.</li>
 * 	 <li>if no such node exists than the node that encloses the range defined by
 *       start and end is returned.</li>
 *   <li>if the length is zero than also nodes are considered where the node's
 *       start or end position matches <code>start</code>.</li>
 *   <li>otherwise <code>null</code> is returned.</li>
 * </ul>
 *
 * @param root the root node from which the search starts
 * @param start the start offset
 * @param length the length
 * @param source the source of the compilation unit
 *
 * @return the result node
 * @throws JavaModelException if an error occurs in the Java model
 *
 * @since		3.0
 */
public static ASTNode perform(ASTNode root, int start, int length, ITypeRoot source) throws JavaModelException {
	NodeFinder finder= new NodeFinder(start, length);
	root.accept(finder);
	ASTNode result= finder.getCoveredNode();
	if (result == null)
		return null;
	Selection selection= Selection.createFromStartLength(start, length);
	if (selection.covers(result)) {
		IBuffer buffer= source.getBuffer();
		if (buffer != null) {
			IScanner scanner= ToolFactory.createScanner(false, false, false, false);
			scanner.setSource(buffer.getText(start, length).toCharArray());
			try {
				int token= scanner.getNextToken();
				if (token != ITerminalSymbols.TokenNameEOF) {
					int tStart= scanner.getCurrentTokenStartPosition();
					if (tStart == result.getStartPosition() - start) {
						scanner.resetTo(tStart + result.getLength(), length - 1);
						token= scanner.getNextToken();
						if (token == ITerminalSymbols.TokenNameEOF)
							return result;
					}
				}
			} catch (InvalidInputException e) {
			}
		}
	}
	return finder.getCoveringNode();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:55,代码来源:NodeFinder.java

示例11: getCompilationUnitNode

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
static CompilationUnit getCompilationUnitNode(IMember member, boolean resolveBindings) {
	ITypeRoot typeRoot= member.getTypeRoot();
    try {
 	if (typeRoot.exists() && typeRoot.getBuffer() != null) {
ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
parser.setSource(typeRoot);
parser.setResolveBindings(resolveBindings);
return (CompilationUnit) parser.createAST(null);
 	}
    } catch (JavaModelException e) {
        JavaPlugin.log(e);
    }
    return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:CallHierarchy.java

示例12: JavaElementLine

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * @param element either an ICompilationUnit or an IClassFile
 * @param lineNumber the line number, starting at 0
 * @param lineStartOffset the start offset of the line
 * @throws CoreException thrown when accessing of the buffer failed
 */
public JavaElementLine(ITypeRoot element, int lineNumber, int lineStartOffset) throws CoreException {
	fElement= element;
	fFlags= 0;

	IBuffer buffer= element.getBuffer();
	if (buffer == null) {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, Messages.format( SearchMessages.JavaElementLine_error_nobuffer, BasicElementLabels.getFileName(element))));
	}

	int length= buffer.getLength();
	int i= lineStartOffset;

	char ch= buffer.getChar(i);
	while (lineStartOffset < length && IndentManipulation.isIndentChar(ch)) {
		ch= buffer.getChar(++i);
	}
	fLineStartOffset= i;

	StringBuffer buf= new StringBuffer();

	while (i < length && !IndentManipulation.isLineDelimiterChar(ch)) {
		if (Character.isISOControl(ch)) {
			buf.append(' ');
		} else {
			buf.append(ch);
		}
		i++;
		if (i < length)
			ch= buffer.getChar(i);
	}
	fLineContents= buf.toString();
	fLineNumber= lineNumber;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:40,代码来源:JavaElementLine.java

示例13: hasSource

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * Checks whether the given Java element has accessible source.
 *
 * @param je the Java element to test
 * @return <code>true</code> if the element has source
 * @since 3.2
 */
private static boolean hasSource(ITypeRoot je) {
	if (je == null || !je.exists())
		return false;

	try {
		return je.getBuffer() != null;
	} catch (JavaModelException ex) {
		IStatus status= new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.OK, "Error in JDT Core during AST creation", ex);  //$NON-NLS-1$
		JavaPlugin.getDefault().getLog().log(status);
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:ASTProvider.java

示例14: JavaElementLine

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * @param element either an ICompilationUnit or an IClassFile
 * @param lineNumber the line number
 * @param lineStartOffset the start offset of the line
 * @throws CoreException thrown when accessing of the buffer failed
 */
public JavaElementLine(ITypeRoot element, int lineNumber, int lineStartOffset) throws CoreException {
	fElement= element;
	fFlags= 0;

	IBuffer buffer= element.getBuffer();
	if (buffer == null) {
		throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, Messages.format( SearchMessages.JavaElementLine_error_nobuffer, BasicElementLabels.getFileName(element))));
	}

	int length= buffer.getLength();
	int i= lineStartOffset;

	char ch= buffer.getChar(i);
	while (lineStartOffset < length && IndentManipulation.isIndentChar(ch)) {
		ch= buffer.getChar(++i);
	}
	fLineStartOffset= i;

	StringBuffer buf= new StringBuffer();

	while (i < length && !IndentManipulation.isLineDelimiterChar(ch)) {
		if (Character.isISOControl(ch)) {
			buf.append(' ');
		} else {
			buf.append(ch);
		}
		i++;
		if (i < length)
			ch= buffer.getChar(i);
	}
	fLineContents= buf.toString();
	fLineNumber= lineNumber;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:40,代码来源:JavaElementLine.java

示例15: rewriteAST

import org.eclipse.jdt.core.ITypeRoot; //导入方法依赖的package包/类
/**
 * Converts all modifications recorded by this rewriter into an object representing the the corresponding text
 * edits to the source of a {@link ITypeRoot} from which the AST was created from.
 * The type root's source itself is not modified by this method call.
 * <p>
 * Important: This API can only be used if the modified AST has been created from a
 * {@link ITypeRoot} with source. That means {@link ASTParser#setSource(ICompilationUnit)},
 * {@link ASTParser#setSource(IClassFile)} or {@link ASTParser#setSource(ITypeRoot)}
 * has been used when initializing the {@link ASTParser}. A {@link IllegalArgumentException} is thrown
 * otherwise. An {@link IllegalArgumentException} is also thrown when the type roots buffer does not correspond
 * anymore to the AST. Use {@link #rewriteAST(IDocument, Map)} for all ASTs created from other content.
 * </p>
 * <p>
 * For nodes in the original that are being replaced or deleted,
 * this rewriter computes the adjusted source ranges
 * by calling {@link TargetSourceRangeComputer#computeSourceRange(ASTNode) getExtendedSourceRangeComputer().computeSourceRange(node)}.
 * </p>
 * <p>
 * Calling this methods does not discard the modifications
 * on record. Subsequence modifications are added to the ones
 * already on record. If this method is called again later,
 * the resulting text edit object will accurately reflect
 * the net cumulative effect of all those changes.
 * </p>
 *
 * @return text edit object describing the changes to the
 * document corresponding to the changes recorded by this rewriter
 * @throws JavaModelException A {@link JavaModelException} is thrown when
 * the underlying compilation units buffer could not be accessed.
 * @throws IllegalArgumentException An {@link IllegalArgumentException}
 * is thrown if the document passed does not correspond to the AST that is rewritten.
 *
 * @since 3.2
 */
public TextEdit rewriteAST() throws JavaModelException, IllegalArgumentException {
	ASTNode rootNode= getRootNode();
	if (rootNode == null) {
		return new MultiTextEdit(); // no changes
	}

	ASTNode root= rootNode.getRoot();
	if (!(root instanceof CompilationUnit)) {
		throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit or class file"); //$NON-NLS-1$
	}
	CompilationUnit astRoot= (CompilationUnit) root;
	ITypeRoot typeRoot = astRoot.getTypeRoot();
	if (typeRoot == null || typeRoot.getBuffer() == null) {
		throw new IllegalArgumentException("This API can only be used if the AST is created from a compilation unit or class file"); //$NON-NLS-1$
	}

	char[] content= typeRoot.getBuffer().getCharacters();
	LineInformation lineInfo= LineInformation.create(astRoot);
	String lineDelim= typeRoot.findRecommendedLineSeparator();
	Map options= typeRoot.getJavaProject().getOptions(true);

	return internalRewriteAST(content, lineInfo, lineDelim, astRoot.getCommentList(), options, rootNode, (RecoveryScannerData)astRoot.getStatementsRecoveryData());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:58,代码来源:ASTRewrite.java


注:本文中的org.eclipse.jdt.core.ITypeRoot.getBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。