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); } }
@Override public boolean visit(ImportDeclaration node) { String name = node.getName().toString(); if (!node.isOnDemand()) { String clzName = StringUtils.substringAfterLast(name, "."); classNameToFullyQualified.put(clzName, name); processInterest(node.getName().toString(), cu.getLineNumber(node.getStartPosition()), "Import of", SourceType.IMPORT); } else { if (lineContainsPackageBlacklist(name)) { for (String knownClz : classNameToFullyQualified.values()) { if (StringUtils.startsWith(knownClz, name)) { processInterest(knownClz, cu.getLineNumber(node.getStartPosition()), "Leads to import of", SourceType.IMPORT); } } } } return true; }
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); } }
/** 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); } }
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); } }
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); } }
@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; }
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; }
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; }
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; }
if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { try { int pos= getScanner().getTokenEndOffset(TerminalTokens.TokenNameimport, node.getStartPosition()); boolean wasStatic= ((Boolean) event.getOriginalValue()).booleanValue(); if (wasStatic) {
if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { try { int pos= getScanner().getTokenEndOffset(TerminalTokens.TokenNameimport, node.getStartPosition()); boolean wasStatic= ((Boolean) event.getOriginalValue()).booleanValue(); if (wasStatic) {
if (event != null && event.getChangeKind() != RewriteEvent.UNCHANGED) { try { int pos= getScanner().getTokenEndOffset(TerminalTokens.TokenNameimport, node.getStartPosition()); boolean wasStatic= ((Boolean) event.getOriginalValue()).booleanValue(); if (wasStatic) {