public static StubTypeContext createStubTypeContext(ICompilationUnit cu, CompilationUnit root, int focalPosition) throws CoreException { StringBuilder bufBefore= new StringBuilder(); StringBuilder bufAfter= new StringBuilder(); 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()); }
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()); }
public static StubTypeContext createStubTypeContext(ICompilationUnit cu, CompilationUnit root, int focalPosition) throws CoreException { IDocument document= RefactoringFileBuffers.acquire(cu).getDocument(); try { StringBuffer bufBefore= new StringBuffer(); StringBuffer bufAfter= new StringBuffer(); int introEnd= 0; PackageDeclaration pack= root.getPackage(); if (pack != null) introEnd= pack.getStartPosition() + pack.getLength(); List imports= root.imports(); if (imports.size() > 0) { ImportDeclaration lastImport= (ImportDeclaration) imports.get(imports.size() - 1); introEnd= lastImport.getStartPosition() + lastImport.getLength(); } try { bufBefore.append(document.get(0, introEnd)); } catch (BadLocationException e) { throw new RuntimeException(e); // doesn't happen } fillWithTypeStubs(bufBefore, bufAfter, focalPosition, root.types()); bufBefore.append(' '); bufAfter.insert(0, ' '); return new StubTypeContext(cu, bufBefore.toString(), bufAfter.toString()); } finally { RefactoringFileBuffers.release(cu); } }
/** 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); } }
ImportDeclaration curr= (ImportDeclaration) decls.get(i); int currOffset= curr.getStartPosition(); int currLength= curr.getLength(); int currExtendedStart = root.getExtendedStartPosition(curr); int currExtendedLen = root.getExtendedLength(curr);
ImportDeclaration curr= (ImportDeclaration) decls.get(i); int currOffset= curr.getStartPosition(); int currLength= curr.getLength(); int currExtendedStart = root.getExtendedStartPosition(curr); int currExtendedLen = root.getExtendedLength(curr);
@Override ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
for (int k= 0; k < importsDecls.size(); k++) { ImportDeclaration decl= (ImportDeclaration) importsDecls.get(k); if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) { if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) { String name= decl.getName().getFullyQualifiedName();
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
for (int k= 0; k < importsDecls.size(); k++) { ImportDeclaration decl= importsDecls.get(k); if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) { if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) { String name= decl.getName().getFullyQualifiedName();
for (int k= 0; k < importsDecls.size(); k++) { ImportDeclaration decl= importsDecls.get(k); if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) { if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) { String name= decl.getName().getFullyQualifiedName();
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
for (int k= 0; k < importsDecls.size(); k++) { ImportDeclaration decl= (ImportDeclaration) importsDecls.get(k); if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) { if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) { String name= decl.getName().getFullyQualifiedName();
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
ASTNode clone0(AST target) { ImportDeclaration result = new ImportDeclaration(target); result.setSourceRange(getStartPosition(), getLength()); result.setOnDemand(isOnDemand()); if (this.ast.apiLevel >= AST.JLS3_INTERNAL) { result.setStatic(isStatic()); } result.setName((Name) getName().clone(target)); return result; }
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; }
@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; }
@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; }