Skip to content

Commit

Permalink
Code improvements in o.e.jdt.ui.examples.javafamily
Browse files Browse the repository at this point in the history
* organize imports
* try with resources
* proper url resolving
* remove useless @see comments
* some pattern matching
  • Loading branch information
akurtakov committed Jan 22, 2025
1 parent 07237c8 commit 013e35b
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation and others.
* Copyright (c) 2003, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,12 +14,13 @@
package org.eclipse.core.indexsearch;

import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;

import org.eclipse.core.resources.IFile;

/**
* An IndeyQuery is used to perform a query against the indexing framework.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.io.Reader;
import java.io.StringReader;

import org.eclipse.jsp.JspTranslator;

import org.eclipse.core.runtime.Assert;

import org.eclipse.jface.text.BadLocationException;
Expand All @@ -26,13 +28,11 @@
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.reconciler.AbstractReconcileStep;
import org.eclipse.jface.text.reconciler.DirtyRegion;
import org.eclipse.jface.text.reconciler.IReconcileStep;
import org.eclipse.jface.text.reconciler.IReconcileResult;
import org.eclipse.jface.text.reconciler.IReconcilableModel;
import org.eclipse.jface.text.reconciler.IReconcileResult;
import org.eclipse.jface.text.reconciler.IReconcileStep;
import org.eclipse.jface.text.source.translation.ITranslator;

import org.eclipse.jsp.JspTranslator;

/**
* This reconcile step has a JSP source document as
* input model and maintains a document that contains the Java
Expand Down Expand Up @@ -66,9 +66,6 @@ protected void initialize() {
fJspTranslator.setTagHandlerFactory(new Jsp2JavaTagHandlerFactory());
}

/*
* @see AbstractReconcileStep#reconcileModel(DirtyRegion, IRegion)
*/
@Override
protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion) {
Assert.isTrue(getInputModel() instanceof DocumentAdapter, "wrong model"); //$NON-NLS-1$
Expand All @@ -88,17 +85,11 @@ protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion sub
return null;
}

/*
* @see AbstractReconcileStep#getModel()
*/
@Override
public IReconcilableModel getModel() {
return fModel;
}

/*
* @see AbstractReconcileStep#convertToInputModel(IReconcileResult[])
*/
@Override
protected IReconcileResult[] convertToInputModel(IReconcileResult[] inputResults) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,11 @@ public class Jsp2JavaTagHandler implements ITagHandler {
private boolean fInJavaSection;


/*
* @see org.eclipse.jface.text.source.ITagHandler#canHandleTag(java.lang.String)
*/
@Override
public boolean canHandleTag(String tag) {
return true;
}

/*
* @see org.eclipse.jface.text.source.ITagHandler#canHandleText(java.lang.String)
*/
@Override
public boolean canHandleText(String text) {
return true;
Expand All @@ -60,9 +54,6 @@ public void reset(String startTag) {
fInJavaSection= "<%".equals(startTag); //$NON-NLS-1$
fInDeclaration= "<%!".equals(startTag); //$NON-NLS-1$
}
/*
* @see org.eclipse.jface.text.source.ITagHandler#addAttribute(java.lang.String, java.lang.String)
*/
@Override
public void addAttribute(String name, String value, int sourceLineNumber) {
if (fInUseBean) {
Expand All @@ -78,9 +69,6 @@ else if ("class".equals(name)) //$NON-NLS-1$
fSource= value;
}

/*
* @see org.eclipse.jface.text.source.ITagHandler#backTranslateOffsetInLine(java.lang.String, int)
*/
@Override
public int backTranslateOffsetInLine(String originalLine, String translatedLine, int offsetInTranslatedLine) {
int javaPartitionStart= 0;
Expand Down Expand Up @@ -128,9 +116,6 @@ private int handleUseBeanTag(String jspLineStr, int relativeLineOffsetInJava) {
return javaPartitionStart - relativeLineOffsetInJava;
}

/*
* @see org.eclipse.jface.text.source.ITagHandler#processEndTag(ITranslatorResultCollector, int)
*/
@Override
public void processEndTag(ITranslatorResultCollector resultCollector, int sourceLineNumber) throws IOException {
Assert.isTrue(resultCollector instanceof JspTranslatorResultCollector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@ public class Jsp2JavaTagHandlerFactory implements ITagHandlerFactory {

private final ITagHandler fTagHandler= new Jsp2JavaTagHandler();

/*
* @see org.eclipse.jface.text.source.IHandlerFactory#getHandler(java.lang.String)
*/
@Override
public ITagHandler getHandler(String tag) {
fTagHandler.reset(tag);
return fTagHandler;
}

/*
* @see org.eclipse.jface.text.source.IHandlerFactory#findHandler(java.lang.String)
*/
@Override
public ITagHandler findHandler(String text) {
return fTagHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

import org.eclipse.jface.text.source.IAnnotationAccess;

import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;

import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.eclipse.ui.editors.text.TextEditor;

import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;


/**
* A simple JSP Editor.
Expand All @@ -46,9 +46,6 @@ public JspEditor() {
// setPreferenceStore(JspUIPlugin.getDefault().getPreferenceStore());
}

/*
* @see TextEditor#createAnnotationAccess()
*/
@Override
protected IAnnotationAccess createAnnotationAccess() {
return new DefaultMarkerAnnotationAccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import org.eclipse.core.resources.IFile;

import org.eclipse.jface.operation.IRunnableWithProgress;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.reconciler.DirtyRegion;
import org.eclipse.jface.text.reconciler.IReconcileStep;
import org.eclipse.jface.text.reconciler.IReconcileResult;
import org.eclipse.jface.text.reconciler.IReconcileStep;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
import org.eclipse.jface.text.source.Annotation;
Expand All @@ -38,6 +39,7 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.actions.WorkspaceModifyOperation;

import org.eclipse.ui.texteditor.ITextEditor;

/**
Expand All @@ -57,45 +59,30 @@ public JspReconcilingStrategy(ISourceViewer sourceViewer, ITextEditor textEditor
fFirstStep= new Jsp2JavaReconcileStep(javaReconcileStep);
}

/*
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument)
*/
@Override
public void setDocument(IDocument document) {
fFirstStep.setInputModel(new DocumentAdapter(document));
}

/*
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
*/
@Override
public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
removeTemporaryAnnotations();
process(fFirstStep.reconcile(dirtyRegion, subRegion));
}

/*
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
*/
@Override
public void reconcile(IRegion partition) {
removeTemporaryAnnotations();
process(fFirstStep.reconcile(partition));
}

/*
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension#setProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public void setProgressMonitor(IProgressMonitor monitor) {
fFirstStep.setProgressMonitor(monitor);
fProgressMonitor= monitor;

}

/*
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension#initialReconcile()
*/
@Override
public void initialReconcile() {
fFirstStep.reconcile(null);
Expand All @@ -108,9 +95,6 @@ private void process(final IReconcileResult[] results) {
return;

IRunnableWithProgress runnable= new WorkspaceModifyOperation(null) {
/*
* @see org.eclipse.ui.actions.WorkspaceModifyOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
for (IReconcileResult r : results) {
Expand Down Expand Up @@ -156,9 +140,9 @@ private void removeTemporaryAnnotations() {

private IFile getFile() {
IEditorInput input= fTextEditor.getEditorInput();
if (!(input instanceof IFileEditorInput))
if (!(input instanceof IFileEditorInput fileInput))
return null;

return ((IFileEditorInput)input).getFile();
return fileInput.getFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public JspSourceViewerConfiguration(ITextEditor textEditor) {
fTextEditor= textEditor;
}

/*
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
*/
@Override
public IReconciler getReconciler(ISourceViewer sourceViewer) {
IReconcilingStrategy reconcilingStrategy= new JspReconcilingStrategy(sourceViewer, fTextEditor);
Expand All @@ -57,17 +54,11 @@ public IReconciler getReconciler(ISourceViewer sourceViewer) {
return reconciler;
}

/*
* @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
*/
@Override
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
return new DefaultAnnotationHover();
}

/*
* @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
*/
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
return new DefaultTextHover(sourceViewer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,13 @@ public ITagHandler registerHandler(String tag) {
return (ITagHandler)fHandlers.remove(tag);
}


/*
* @see org.eclipse.jface.text.source.ITagHandlerFactory#getHandler(java.lang.String)
*/
@Override
public ITagHandler getHandler(String tag) {
Assert.isNotNull(tag);

return (ITagHandler)fHandlers.get(tag);
}

/*
* @see org.eclipse.jface.text.source.ITagHandlerFactory#findHandler(java.lang.String)
*/
@Override
public ITagHandler findHandler(String text) {
Assert.isNotNull(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public class JspPluginImages {
static {
String pathSuffix = "icons/full/"; //$NON-NLS-1$

try {
ICON_BASE_URL= new URL(JspUIPlugin.getDefault().getBundle().getEntry("/"), pathSuffix); //$NON-NLS-1$
} catch (MalformedURLException e) {
// do nothing
}
ICON_BASE_URL= JspUIPlugin.getDefault().getBundle().getEntry("/"+ pathSuffix); //$NON-NLS-1$
}

// Use IPath and toOSString to build the names to ensure they have the slashes correct
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation and others.
* Copyright (c) 2003, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,18 +14,22 @@
package org.eclipse.jsp;

import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;

import org.eclipse.core.indexsearch.IIndex;
import org.eclipse.core.indexsearch.IIndexQuery;
import org.eclipse.core.indexsearch.ISearchResultCollector;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.indexsearch.*;
import org.eclipse.core.indexsearch.IIndexQuery;

import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;

Expand Down
Loading

0 comments on commit 013e35b

Please sign in to comment.