private void showInSourceViewer(final ISourceReference selected) throws JavaModelException { if (selected == null) setSourceViewerContents(null); else setSourceViewerContents(selected.getSource()); }
ISourceReference reference = (ISourceReference) owner; String contents = reference.getSource(); ISourceRange range = (ISourceRange)reference.getSourceRange(); int correctedStart = start - range.getOffset(); // Math.min should be redundant (no JavaElement should contain half of a comment) int correctedEnd = Math.min( (end - range.getOffset()) , range.getLength()); //System.out.println("Checking for sentinel: " + contents.substring(correctedStart, correctedEnd)); boolean keepScanning = true; int shift = correctedStart+2; // +2 refers to the // characters which we know we can remove while(keepScanning && shift <= correctedEnd) { char nextChar = contents.charAt(shift); if(nextChar != ' ' && nextChar != '\t') { keepScanning = false; } else { shift++; } }
private void showInSourceViewer(final ISourceReference selected) throws JavaModelException { if (selected == null) setSourceViewerContents(null); else setSourceViewerContents(selected.getSource()); }
public String run(int offset, int length) throws JavaModelException { ISourceReference sr= getSourceReference(); if (sr.getSourceRange() == null) { return SearchMessages.FindOccurrencesEngine_noSource_text; } final CompilationUnit root= createAST(); if (root == null) { return SearchMessages.FindOccurrencesEngine_cannotParse_text; } String message= fFinder.initialize(root, offset, length); if (message != null) return message; final IDocument document= new Document(getSourceReference().getSource()); performNewSearch(fFinder, document, getInput()); return null; }
public final Reader getSourceFile(String packagename, String sourcename) throws IOException { try { packagename = packagename.replace('/', '.'); final IPackageFragment pkg = root.getPackageFragment(packagename); final String source = getSourceReference(pkg, sourcename).getSource(); if (source != null) { return new StringReader(source); } else { return null; } } catch (CoreException e) { final IOException ioException = new IOException(e.getMessage()); throw (IOException) ioException.initCause(e); } }
private void showInSourceViewer(final ISourceReference selected) throws JavaModelException { if (selected == null) setSourceViewerContents(null); else setSourceViewerContents(selected.getSource()); }
private void computeFoldingStructure(FoldingStructureComputationContext ctx) { IParent parent= (IParent) fInput; try { if (!(fInput instanceof ISourceReference)) return; String source= ((ISourceReference)fInput).getSource(); if (source == null) return; ctx.getScanner().setSource(source.toCharArray()); computeFoldingStructure(parent.getChildren(), ctx); } catch (JavaModelException x) { } }
private String getContents(CompilationUnit root) { try { IJavaElement rootElem= root.getJavaElement(); if ((rootElem instanceof ISourceReference)) return ((ISourceReference)rootElem).getSource(); else return null; } catch (JavaModelException e) { //We must handle it here because JavaEditor does not expect an exception /* showing a dialog here would be too heavy but we cannot just * swallow the exception */ JavaPlugin.log(e); return null; } }
private void computeFoldingStructure(FoldingStructureComputationContext ctx) { IParent parent= (IParent) fInput; try { if (!(fInput instanceof ISourceReference)) return; String source= ((ISourceReference)fInput).getSource(); if (source == null) return; ctx.getScanner().setSource(source.toCharArray()); computeFoldingStructure(parent.getChildren(), ctx); } catch (JavaModelException x) { } }
private void computeFoldingStructure(FoldingStructureComputationContext ctx) { IParent parent= (IParent) fInput; try { if (!(fInput instanceof ISourceReference)) return; String source= ((ISourceReference)fInput).getSource(); if (source == null) return; ctx.getScanner().setSource(source.toCharArray()); computeFoldingStructure(parent.getChildren(), ctx); } catch (JavaModelException x) { } }
private static String getSourceOfDeclararationNode(IJavaElement elem, ICompilationUnit cu) throws JavaModelException, CoreException { Assert.isTrue(elem.getElementType() != IJavaElement.IMPORT_CONTAINER); if (elem instanceof ISourceReference) { ISourceReference reference= (ISourceReference) elem; String source= reference.getSource(); if (source != null) return Strings.trimIndentation(source, cu.getJavaProject(), false); } return ""; //$NON-NLS-1$ } }
private static String getSourceOfDeclararationNode(IJavaElement elem, ICompilationUnit cu) throws JavaModelException, CoreException { Assert.isTrue(elem.getElementType() != IJavaElement.IMPORT_CONTAINER); if (elem instanceof ISourceReference) { ISourceReference reference= (ISourceReference) elem; String source= reference.getSource(); if (source != null) return Strings.trimIndentation(source, cu.getJavaProject(), false); } return ""; //$NON-NLS-1$ } }
private static String getSourceOfDeclararationNode(IJavaElement elem, ICompilationUnit cu) throws JavaModelException, CoreException { Assert.isTrue(elem.getElementType() != IJavaElement.IMPORT_CONTAINER); if (elem instanceof ISourceReference) { ISourceReference reference= (ISourceReference) elem; String source= reference.getSource(); if (source != null) return Strings.trimIndentation(source, cu.getJavaProject(), false); } return ""; //$NON-NLS-1$ } }
private static String getUnindentedSource(ISourceReference sourceReference) throws JavaModelException { String[] lines= Strings.convertIntoLines(sourceReference.getSource()); final IJavaProject project= ((IJavaElement) sourceReference).getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed((IJavaElement) sourceReference)); }
private static String getUnindentedSource(ISourceReference sourceReference) throws JavaModelException { String[] lines= Strings.convertIntoLines(sourceReference.getSource()); final IJavaProject project= ((IJavaElement) sourceReference).getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed((IJavaElement) sourceReference)); }
private static String getUnindentedSource(ISourceReference sourceReference) throws JavaModelException { String[] lines= Strings.convertIntoLines(sourceReference.getSource()); final IJavaProject project= ((IJavaElement) sourceReference).getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed((IJavaElement) sourceReference)); }
private static String getUnindentedSource(ISourceReference sourceReference) throws JavaModelException { Assert.isTrue(sourceReference instanceof IJavaElement); String[] lines= Strings.convertIntoLines(sourceReference.getSource()); final IJavaProject project= ((IJavaElement) sourceReference).getJavaProject(); Strings.trimIndentation(lines, project, false); return Strings.concatenate(lines, StubUtility.getLineDelimiterUsed((IJavaElement) sourceReference)); }
/** * Computes and returns the offset in the unclipped document based on the given text selection * from the clipped document. * * @param textSelection the text selection * @return the offset in the unclipped document or <code>-1</code> if the offset cannot be * computed */ private int getOffsetInUnclippedDocument(ITextSelection textSelection) { IDocument unclippedDocument= null; try { unclippedDocument= new Document(((ISourceReference)fCurrentViewInput).getSource()); } catch (JavaModelException e) { return -1; } IDocument clippedDoc= (IDocument)fViewer.getInput(); try { IRegion unclippedLineInfo= unclippedDocument.getLineInformation(fCommentLineCount + textSelection.getStartLine()); IRegion clippedLineInfo= clippedDoc.getLineInformation(textSelection.getStartLine()); int removedIndentation= unclippedLineInfo.getLength() - clippedLineInfo.getLength(); int relativeLineOffset= textSelection.getOffset() - clippedLineInfo.getOffset(); return unclippedLineInfo.getOffset() + removedIndentation + relativeLineOffset ; } catch (BadLocationException ex) { return -1; } }
/** * Computes and returns the offset in the unclipped document * based on the given text selection from the clipped * document. * * @param textSelection * @return the offest in the unclipped document or <code>-1</code> if the offset cannot be computed */ private int getOffsetInUnclippedDocument(ITextSelection textSelection) { IDocument unclippedDocument= null; try { unclippedDocument= new Document(((ISourceReference)fCurrentViewInput).getSource()); } catch (JavaModelException e) { return -1; } IDocument clippedDoc= (IDocument)fViewer.getInput(); try { IRegion unclippedLineInfo= unclippedDocument.getLineInformation(fCommentLineCount + textSelection.getStartLine()); IRegion clippedLineInfo= clippedDoc.getLineInformation(textSelection.getStartLine()); int removedIndentation= unclippedLineInfo.getLength() - clippedLineInfo.getLength(); int relativeLineOffset= textSelection.getOffset() - clippedLineInfo.getOffset(); return unclippedLineInfo.getOffset() + removedIndentation + relativeLineOffset ; } catch (BadLocationException ex) { return -1; } }