Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public ClassFileDocumentProvider() {
protected boolean setDocumentContent(IDocument document, IEditorInput editorInput, String encoding) throws CoreException {
if (editorInput instanceof IClassFileEditorInput) {
IClassFile classFile= ((IClassFileEditorInput) editorInput).getClassFile();
String source= classFile.getSource();
String source= getSourceIfPresent(classFile);
if (source == null)
source= ""; //$NON-NLS-1$
document.set(source);
Expand All @@ -218,6 +218,15 @@ protected boolean setDocumentContent(IDocument document, IEditorInput editorInpu
return super.setDocumentContent(document, editorInput, encoding);
}

private String getSourceIfPresent(IClassFile classFile) {
try {
return classFile.getSource();
} catch (JavaModelException e) {
//Assume no source...
return null;
}
}

/**
* Creates an annotation model derived from the given class file editor input.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,21 +674,6 @@ private void doSetInputCached(IEditorInput input) throws CoreException {
message,
null));
}

JavaModelException e= probeInputForSource(input);
if (e != null) {
IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) input;
IClassFile file= classFileEditorInput.getClassFile();
IJavaProject javaProject= file.getJavaProject();
if (!javaProject.exists() || !javaProject.isOnClasspath(file)) {
throw new CoreException(JavaUIStatus.createError(
IJavaModelStatusConstants.INVALID_RESOURCE,
JavaEditorMessages.ClassFileEditor_error_classfile_not_on_classpath,
null));
}
throw e;
}

IDocumentProvider documentProvider= getDocumentProvider();
if (documentProvider instanceof ClassFileDocumentProvider) {
((ClassFileDocumentProvider) documentProvider).removeInputChangeListener(this);
Expand Down Expand Up @@ -779,23 +764,6 @@ private void createPartControlCached(Composite parent) {
}
}

private JavaModelException probeInputForSource(IEditorInput input) {
if (input == null) {
return null;
}

IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) input;
IClassFile file= classFileEditorInput.getClassFile();

try {
file.getSourceRange();
} catch (JavaModelException e) {
return e;
}

return null;
}

/**
* Checks if the class file input has no source attached. If so, a source attachment form is shown.
*
Expand All @@ -816,7 +784,7 @@ private void verifyInput(IEditorInput input) throws JavaModelException {
boolean wasUsingSourceCopyAction= fSourceCopyAction == getAction(ITextEditorActionConstants.COPY);

// show source attachment form if no source found
if (file.getSourceRange() == null) {
if (!hasSource(file)) {
// dispose old source attachment form
if (fSourceAttachmentForm != null) {
fSourceAttachmentForm.dispose();
Expand Down Expand Up @@ -905,6 +873,15 @@ public void run() {
}
}

private static boolean hasSource(IClassFile file) {
try {
return file.getSourceRange() != null;
} catch (JavaModelException e) {
//assume no source then...
return false;
}
}

/*
* @see ClassFileDocumentProvider.InputChangeListener#inputChanged(IClassFileEditorInput)
*/
Expand Down
Loading