本文整理汇总了Java中org.eclipse.jdt.core.dom.ImportDeclaration.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java ImportDeclaration.getLength方法的具体用法?Java ImportDeclaration.getLength怎么用?Java ImportDeclaration.getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.ImportDeclaration
的用法示例。
在下文中一共展示了ImportDeclaration.getLength方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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());
}
示例3: 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);
}
}
示例4: 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;
}
示例5: 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);
}