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


Java ImportDeclaration.getStartPosition方法代码示例

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


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

示例1: createStubTypeContext

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
public static StubTypeContext createStubTypeContext(
    ICompilationUnit cu, CompilationUnit root, int focalPosition) throws CoreException {
  StringBuffer bufBefore = new StringBuffer();
  StringBuffer bufAfter = new StringBuffer();

  int introEnd = 0;
  PackageDeclaration pack = root.getPackage();
  if (pack != null) introEnd = pack.getStartPosition() + pack.getLength();
  List<ImportDeclaration> imports = root.imports();
  if (imports.size() > 0) {
    ImportDeclaration lastImport = imports.get(imports.size() - 1);
    introEnd = lastImport.getStartPosition() + lastImport.getLength();
  }
  bufBefore.append(cu.getBuffer().getText(0, introEnd));

  fillWithTypeStubs(bufBefore, bufAfter, focalPosition, root.types());
  bufBefore.append(' ');
  bufAfter.insert(0, ' ');
  return new StubTypeContext(cu, bufBefore.toString(), bufAfter.toString());
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:TypeContextChecker.java

示例2: createStubTypeContext

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
public static StubTypeContext createStubTypeContext(ICompilationUnit cu, CompilationUnit root, int focalPosition) throws CoreException {
	StringBuffer bufBefore= new StringBuffer();
	StringBuffer bufAfter= new StringBuffer();

	int introEnd= 0;
	PackageDeclaration pack= root.getPackage();
	if (pack != null)
		introEnd= pack.getStartPosition() + pack.getLength();
	List<ImportDeclaration> imports= root.imports();
	if (imports.size() > 0) {
		ImportDeclaration lastImport= imports.get(imports.size() - 1);
		introEnd= lastImport.getStartPosition() + lastImport.getLength();
	}
	bufBefore.append(cu.getBuffer().getText(0, introEnd));

	fillWithTypeStubs(bufBefore, bufAfter, focalPosition, root.types());
	bufBefore.append(' ');
	bufAfter.insert(0, ' ');
	return new StubTypeContext(cu, bufBefore.toString(), bufAfter.toString());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:TypeContextChecker.java

示例3: evaluateReplaceRange

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
private IRegion evaluateReplaceRange(CompilationUnit root) {
	List imports= root.imports();
	if (!imports.isEmpty()) {
		ImportDeclaration first= (ImportDeclaration) imports.get(0);
		ImportDeclaration last= (ImportDeclaration) imports.get(imports.size() - 1);

		int startPos= first.getStartPosition(); // no extended range for first: bug 121428
		int endPos= root.getExtendedStartPosition(last) + root.getExtendedLength(last);
		int endLine= root.getLineNumber(endPos);
		if (endLine > 0) {
			int nextLinePos= root.getPosition(endLine + 1, 0);
			if (nextLinePos >= 0) {
				int firstTypePos= getFirstTypeBeginPos(root);
				if (firstTypePos != -1 && firstTypePos < nextLinePos) {
					endPos= firstTypePos;
				} else {
					endPos= nextLinePos;
				}
			}
		}
		return new Region(startPos, endPos - startPos);
	} else {
		int start= getPackageStatementEndPos(root);
		return new Region(start, 0);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:27,代码来源:ImportRewriteAnalyzer.java

示例4: addImportsTree

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
/** Add imports as single node to foldable tree */
protected void addImportsTree() {

	@SuppressWarnings("unchecked")
	final List<ImportDeclaration> imports = (List<ImportDeclaration>) cu.imports();
	if (!imports.isEmpty()) {

		// Get range of imports (starting after first import statement)
		final ImportDeclaration firstImport = imports.get(0);
		final int startChar = firstImport.getStartPosition() + firstImport.getLength() - 1;
		final ImportDeclaration lastImport = imports.get(imports.size() - 1);
		final int endChar = lastImport.getStartPosition() + lastImport.getLength() - 1;

		// Add import identifiers to identifier list
		final List<String> importIdentifiers = Lists.newArrayList();
		for (final ImportDeclaration importNode : imports)
			putTokenizedImports(importIdentifiers, importNode.getName().getFullyQualifiedName());

		// Remove import identifiers from root token list
		tree.getRoot().removeTerms(importIdentifiers);

		// Add imports as single node to tree
		final ImportDeclaration node = cu.getAST().newImportDeclaration();
		node.setSourceRange(startChar, endChar - startChar + 1);
		final FoldableNode fn = tree.new FoldableNode(node);
		fn.addTerms(importIdentifiers);
		tree.getRoot().addChild(fn);

		// Add import range to allFolds
		importBlock = Range.closed(startChar, endChar);
		allFolds.add(importBlock);
	}
}
 
开发者ID:mast-group,项目名称:tassal,代码行数:34,代码来源:ASTVisitors.java

示例5: visit

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
@Override
public boolean visit(ImportDeclaration node) {
       int s= node.getStartPosition();
       int l= node.getLength();
       int declarationEnd= s + l;
       if (fImportContainer == null)
           fImportContainer= new JavaNode(getCurrentContainer(), JavaNode.IMPORT_CONTAINER, null, s, l);
       String nm= node.getName().toString();
       if (node.isOnDemand())
           nm+= ".*"; //$NON-NLS-1$
       new JavaNode(fImportContainer, JavaNode.IMPORT, nm, s, l);
       fImportContainer.setLength(declarationEnd - fImportContainer.getRange().getOffset() + 1);
       fImportContainer.setAppendPosition(declarationEnd + 2); // FIXME
       return false;
   }
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:JavaParseTreeBuilder.java

示例6: addImportDeclEntry

import org.eclipse.jdt.core.dom.ImportDeclaration; //导入方法依赖的package包/类
/**
 * adds the import entry, but if its an existing import entry then preserves the comments surrounding the import
 */
private ImportDeclEntry addImportDeclEntry(String containerName, String fullTypeName, boolean isStatic, CompilationUnit root) {
	List/*ImportDeclaration*/ decls= root.imports();
	if (decls.isEmpty() || this.preserveExistingCommentsRanges == null || this.preserveExistingCommentsRanges.length == 0) {
		return new ImportDeclEntry(containerName.length(), fullTypeName, isStatic, null);
	}
	IRegion precedingCommentRange = null;
	IRegion trailingCommentRange = null;
	int prevOffset = this.replaceRange.getOffset();  // will store offset of the previous import's extended end
	int numOfImports = decls.size();
	for (int i= 0; i < numOfImports; i++) {
		ImportDeclaration curr= (ImportDeclaration) decls.get(i);
		int currOffset= curr.getStartPosition();
		int currLength= curr.getLength();
		int currExtendedStart = root.getExtendedStartPosition(curr);
		int currExtendedLen = root.getExtendedLength(curr);
		String name= getFullName(curr);
		String packName= getQualifier(curr);
		if (packName.equals(containerName) && (name.equals(fullTypeName) || name.endsWith("*"))) {//$NON-NLS-1$
			int preserveCommentsLen = this.preserveExistingCommentsRanges.length;
			for (int j = 0; j < preserveCommentsLen; j++) {
				int offset = this.preserveExistingCommentsRanges[j].getOffset();
				boolean wasRangeUsed = false;
				int existingCommentLength = this.preserveExistingCommentsRanges[j].getLength();
				if (offset == currExtendedStart) {
					// comments belonging to this import's extended start
					precedingCommentRange = new Region(offset, existingCommentLength);
					wasRangeUsed = true;
				} else if (offset < currExtendedStart && offset > prevOffset) {
					// comment between two imports but not inside either's extended ranges
					// to preserve the position of these comments add a dummy comment entry
					PackageEntry commentEntry = new PackageEntry(); // create a comment package entry for this
					commentEntry.setGroupID(packName);	// the comment should belong to the current group
					this.packageEntries.add(commentEntry);
					commentEntry.add(new ImportDeclEntry(packName.length(), null, false, new Region(offset, existingCommentLength)));
					wasRangeUsed = true;
				} else if ((currExtendedStart + currExtendedLen) != (currOffset + currLength)){
					if (offset == currOffset + currLength) {
						// comment is in the extended end of the import
						trailingCommentRange = new Region(offset, existingCommentLength);
						wasRangeUsed = true;
					} else if (offset > (currOffset + currLength)) {
						break;
					}
				}
				if (wasRangeUsed) {
					// remove this comment from preserveExistingCommentsRanges array
					IRegion[] tempRegions = new IRegion[--preserveCommentsLen];
					System.arraycopy(this.preserveExistingCommentsRanges, 0, tempRegions, 0, j);
					System.arraycopy(this.preserveExistingCommentsRanges, j+1, tempRegions, j, tempRegions.length - j);
					this.preserveExistingCommentsRanges = tempRegions;
					j--;
				}
			}
			return new ImportDeclEntry(containerName.length(), fullTypeName, isStatic, null, precedingCommentRange, trailingCommentRange);
		}
		prevOffset = currExtendedStart + currExtendedLen - 1;
	}
	return new ImportDeclEntry(containerName.length(), fullTypeName, isStatic, null);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:63,代码来源:ImportRewriteAnalyzer.java


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