Skip to content

Commit

Permalink
Getting rid of some console warnings by:
Browse files Browse the repository at this point in the history
* Using generic types to get rid of `unchecked` warnings
* Replacing deprecated calls with suggested alternatives

Minor code improvements:
* Removing unused imports
* Removing unused and commented out code (not touched since years)
* Removed empty if statement and unnecessary double braces
* Adding missing `@Override` annotation
  • Loading branch information
asbachb committed Jun 27, 2023
1 parent 297109f commit 62d04cf
Show file tree
Hide file tree
Showing 27 changed files with 176 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class JspColoringData extends PropertyChangeSupport {
public static final String PROP_PARSING_IN_PROGRESS = "parsingInProgress"; //NOI18N

/** Taglib id -> TagLibraryInfo */
private Map taglibs;
private Map<String, TagLibraryInfo> taglibs;

/** Prefix -> Taglib id */
private Map<String, String> prefixMapper;
Expand Down Expand Up @@ -120,7 +120,7 @@ public void parsingStarted() {
* @param newPrefixMapper the new map of (prefix, uri)
* @param parseSuccessful whether parsing was successful. If false, then the new information is partial only
*/
public void applyParsedData(Map newTaglibs, Map<String, String> newPrefixMapper, boolean newELIgnored, boolean newXMLSyntax, boolean parseSuccessful) {
public void applyParsedData(Map<String, TagLibraryInfo> newTaglibs, Map<String, String> newPrefixMapper, boolean newELIgnored, boolean newXMLSyntax, boolean parseSuccessful) {

initialized = true;

Expand Down Expand Up @@ -165,7 +165,7 @@ public void applyParsedData(Map newTaglibs, Map<String, String> newPrefixMapper,
String uri = newPrefixMapper.get(prefix);
String uriOld = prefixMapper.get(prefix);
if ((uriOld == null) || !uri.equals(uriOld)) {
Object newTaglib = newTaglibs.get(uri);
TagLibraryInfo newTaglib = newTaglibs.get(uri);
if (newTaglib != null) {
// change - merge it
prefixMapper.put(prefix, uri);
Expand All @@ -180,8 +180,8 @@ public void applyParsedData(Map newTaglibs, Map<String, String> newPrefixMapper,
}
}

private static boolean equalsColoringInformation(Map taglibs1, Map<String, String> prefixMapper1,
Map taglibs2, Map<String, String> prefixMapper2) {
private static boolean equalsColoringInformation(Map<String, TagLibraryInfo> taglibs1, Map<String, String> prefixMapper1,
Map<String, TagLibraryInfo> taglibs2, Map<String, String> prefixMapper2) {

if ((taglibs1 == null) != (taglibs2 == null)) {
return false;
Expand All @@ -203,8 +203,8 @@ private static boolean equalsColoringInformation(Map taglibs1, Map<String, Strin
return false;
}

TagLibraryInfo tli1 = (TagLibraryInfo)taglibs1.get(key1);
TagLibraryInfo tli2 = (TagLibraryInfo)taglibs2.get(key2);
TagLibraryInfo tli1 = taglibs1.get(key1);
TagLibraryInfo tli2 = taglibs2.get(key2);
if ((tli1 == null) || (tli2 == null)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
Expand Down Expand Up @@ -273,14 +271,6 @@ public String getScriptingLanguage() {
return "text/x-java"; // NOI18N
}

/**
* Ensures the file encoding is determined. The call may may access
* JSP parser and obtain project's lock.
*/
void loadFileEncoding() {
getFileEncoding();
}

String getFileEncoding() {
//just assure we do not return the initial null value
encoding.compareAndSet(null, findFileEncoding(false));
Expand Down Expand Up @@ -349,10 +339,6 @@ private void checkRefreshServlet() {
((dObj == null) ? "null" : dObj.getClass().getName()) + // NOI18N
"/" + dObj); // NOI18N
}
/*if (!(dObj instanceof JspServletDataObject)) {
// need to re-recognize
dObj = rerecognize(dObj);
}*/
if (dObj instanceof JspServletDataObject) {
servletDataObject = (JspServletDataObject)dObj;
servletDataObjectDate = dObj.getPrimaryFile().lastModified();
Expand Down Expand Up @@ -385,8 +371,7 @@ private void checkRefreshServlet() {
}

// editor
if ((oldServlet == null)/*&&(servletDataObject != null)*/) {
} else {
if (oldServlet != null) {
RequestProcessor.postRequest(
new Runnable() {
public void run() {
Expand All @@ -401,26 +386,6 @@ public void run() {
}
}

/** This method causes a DataObject to be re-recognized by the loader system.
* This is a poor practice and should not be normally used, as it uses reflection
* to call a protected method DataObject.dispose().
*/
/* private DataObject rerecognize(DataObject dObj) {
// invalidate the object so it can be rerecognized
FileObject prim = dObj.getPrimaryFile();
try {
dObj.setValid(false);
return DataObject.find(prim);
}
catch (java.beans.PropertyVetoException e) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
}
catch (DataObjectNotFoundException e) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
}
return dObj;
}*/

/** JDK 1.2 compiler hack. */
public void firePropertyChange0(String propertyName, Object oldValue, Object newValue) {
super.firePropertyChange(propertyName, oldValue, newValue);
Expand Down Expand Up @@ -497,18 +462,18 @@ protected FileObject handleMove(DataFolder df) throws IOException {
////// -------- INNER CLASSES ---------

private class Listener extends FileChangeAdapter implements PropertyChangeListener/*, ServerRegistryImpl.ServerRegistryListener */{
WeakReference weakListener;
WeakReference<FileChangeListener> weakListener;

Listener() {
}

private void register(FileObject fo) {
EventListener el = WeakListeners.create(FileChangeListener.class, this, fo);
fo.addFileChangeListener((FileChangeListener) el);
weakListener = new WeakReference(el);
FileChangeListener el = WeakListeners.create(FileChangeListener.class, this, fo);
fo.addFileChangeListener(el);
weakListener = new WeakReference<>(el);
}
private void unregister(FileObject fo) {
FileChangeListener listener = (FileChangeListener) weakListener.get();
FileChangeListener listener = weakListener.get();
if (listener != null) {
fo.removeFileChangeListener(listener);
}
Expand Down Expand Up @@ -549,31 +514,6 @@ public void propertyChange(PropertyChangeEvent evt) {
public void fileRenamed(FileRenameEvent fe) {
refreshPlugin(true);
}

// implementation of ServerRegistryImpl.ServerRegistryListener
/*
PENDING
public void added(ServerRegistryImpl.ServerEvent added) {
serverChange();
}
public void setAppDefault(ServerRegistryImpl.InstanceEvent inst) {
serverChange();
}
public void setWebDefault(ServerRegistryImpl.InstanceEvent inst) {
serverChange();
}
public void removed(ServerRegistryImpl.ServerEvent removed) {
serverChange();
}
*/
/*
private void serverChange() {
refreshPlugin(true);
firePropertyChange0(PROP_SERVER_CHANGE, null, null);
}*/
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.swing.Action;
import org.openide.nodes.*;
import org.openide.loaders.DataNode;
import org.openide.loaders.DataObject;
Expand Down Expand Up @@ -58,14 +59,18 @@ public JspNode (JspDataObject jdo) {

private void initialize () {
setIconBaseWithExtension(getIconBase());
setDefaultAction (SystemAction.get (OpenAction.class));

if (isTagFile())
setShortDescription (NbBundle.getMessage(JspNode.class, "LBL_tagNodeShortDesc")); //NOI18N
else
setShortDescription (NbBundle.getMessage(JspNode.class, "LBL_jspNodeShortDesc")); //NOI18N
}

@Override
public Action getPreferredAction() {
return SystemAction.get (OpenAction.class);
}

private String getExtension(){
return getDataObject().getPrimaryFile().getExt();
}
Expand Down Expand Up @@ -98,26 +103,21 @@ protected Sheet createSheet () {
ps.setDisplayName(NbBundle.getBundle(JspNode.class).getString("PROP_executionSetName")); //NOI18N
ps.setShortDescription(NbBundle.getBundle(JspNode.class).getString("HINT_executionSetName")); //NOI18N

ps.put(new PropertySupport.ReadWrite (
ps.put(new PropertySupport.ReadWrite<String> (
PROP_REQUEST_PARAMS,
String.class,
NbBundle.getBundle(JspNode.class).getString("PROP_requestParams"), //NOI18N
NbBundle.getBundle(JspNode.class).getString("HINT_requestParams") //NOI18N
) {
public Object getValue() {
public String getValue() {
return getRequestParams(((MultiDataObject)getDataObject()).getPrimaryEntry());
}
public void setValue (Object val) throws InvocationTargetException {
if (val instanceof String) {
try {
setRequestParams(((MultiDataObject)getDataObject()).getPrimaryEntry(), (String)val);
} catch(IOException e) {
throw new InvocationTargetException (e);
}
}
else {
throw new IllegalArgumentException();
}
public void setValue (String val) throws InvocationTargetException {
try {
setRequestParams(((MultiDataObject)getDataObject()).getPrimaryEntry(), (String)val);
} catch(IOException e) {
throw new InvocationTargetException (e);
}
}
}
);
Expand All @@ -136,13 +136,13 @@ public void setValue (Object val) throws InvocationTargetException {
ps.setShortDescription(NbBundle.getBundle(JspNode.class).getString("HINT_textfileSetName")); // NOI18N
sheet.put(ps);

ps.put(new PropertySupport.ReadOnly(
ps.put(new PropertySupport.ReadOnly<String>(
PROP_FILE_ENCODING,
String.class,
NbBundle.getBundle(JspNode.class).getString("PROP_fileEncoding"), //NOI18N
NbBundle.getBundle(JspNode.class).getString("HINT_fileEncoding") //NOI18N
) {
public Object getValue() {
public String getValue() {
return ((JspDataObject)getDataObject()).getFileEncoding();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.ref.WeakReference;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -67,7 +68,7 @@ public class TagLibParseSupport implements org.openide.nodes.Node.Cookie, TagLib
// private static final int WAIT_FOR_EDITOR_TIMEOUT = 15 * 1000; //15 seconds

/** Holds a reference to the JSP coloring data. */
private WeakReference jspColoringDataRef;
private WeakReference<JspColoringData> jspColoringDataRef;

/** Holds a time-based cache of the JspOpenInfo structure. */
private TimeReference jspOpenInfoRef;
Expand All @@ -76,13 +77,13 @@ public class TagLibParseSupport implements org.openide.nodes.Node.Cookie, TagLib
* The editor should hold a strong reference to this object. That way, if the editor window
* is closed, memory is reclaimed, but important data is kept when it is needed.
*/
private SoftReference parseResultRef;
private SoftReference<JspParserAPI.ParseResult> parseResultRef;

/** Holds the last successful parse result: JspParserAPI.ParseResult.
* The editor should hold a strong reference to this object. That way, if the editor window
* is closed, memory is reclaimed, but important data is kept when it is needed.
*/
private SoftReference parseResultSuccessfulRef;
private SoftReference<JspParserAPI.ParseResult> parseResultSuccessfulRef;

private final Object parseResultLock = new Object();
private final Object openInfoLock = new Object();
Expand Down Expand Up @@ -136,7 +137,7 @@ JspColoringData getJSPColoringData(boolean prepare) {
return (JspColoringData)o;
}
JspColoringData jcd = new JspColoringData(this);
jspColoringDataRef = new WeakReference(jcd);
jspColoringDataRef = new WeakReference<>(jcd);
if (prepare) {
prepare();
}
Expand Down Expand Up @@ -280,9 +281,9 @@ public JspParserAPI.ParseResult getCachedParseResult(boolean successfulOnly, boo
}

JspParserAPI.ParseResult ret = null;
SoftReference myRef = successfulOnly ? parseResultSuccessfulRef : parseResultRef;
SoftReference<JspParserAPI.ParseResult> myRef = successfulOnly ? parseResultSuccessfulRef : parseResultRef;
if (myRef != null) {
ret = (JspParserAPI.ParseResult)myRef.get();
ret = myRef.get();
}

if ((ret == null) && (!successfulOnly)) {
Expand Down Expand Up @@ -341,9 +342,9 @@ public void run() {
assert locResult != null;

synchronized (TagLibParseSupport.this.parseResultLock) {
parseResultRef = new SoftReference(locResult);
parseResultRef = new SoftReference<>(locResult);
if (locResult.isParsingSuccess()) {
parseResultSuccessfulRef = new SoftReference(locResult);
parseResultSuccessfulRef = new SoftReference<>(locResult);
//hold a reference to the parsing data until last editor pane is closed
//motivation: the editor doesn't always hold a strogref to this object
//so the SoftRef is sometime cleaned even if there is an editor pane opened.
Expand All @@ -361,7 +362,7 @@ public void run() {
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ArrayList<ErrorInfo> errors = new ArrayList<ErrorInfo>(locResult.getErrors().length);
List<ErrorInfo> errors = new ArrayList<>(locResult.getErrors().length);
for (int i = 0; i < locResult.getErrors().length; i ++){
JspParserAPI.ErrorDescriptor err = locResult.getErrors()[i];
if (err != null && checkError(err)) {
Expand All @@ -387,9 +388,6 @@ public void run() {
parsingTask = null;

if (pageInfo == null) return;
//Map prefixMapper = (pageInfo.getXMLPrefixMapper().size() > 0) ?
// pageInfo.getApproxXmlPrefixMapper() : pageInfo.getJspPrefixMapper();
//Map prefixMapper = pageInfo.getJspPrefixMapper();
Map<String, String> prefixMapper = null;
if (pageInfo.getXMLPrefixMapper().size() > 0) {
prefixMapper = pageInfo.getApproxXmlPrefixMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,32 +272,29 @@ private static void insertTagLibRef(JTextComponent target, String prefix, String
Document doc = target.getDocument();
if (doc instanceof BaseDocument) {
BaseDocument baseDoc = (BaseDocument)doc;
baseDoc.atomicLock();
try {
int pos = 0; // FIXME: compute better where to insert tag lib definition?
String definition = "<%@taglib prefix=\""+prefix+"\" uri=\""+uri+"\"%>\n"; //NOI18N

//test for .jspx. FIXME: find better way to detect xml syntax?.
FileObject fobj = getFileObject(target);
if (fobj != null && "jspx".equals(fobj.getExt())) {
int baseDocLength = baseDoc.getLength();
String text = baseDoc.getText(0, baseDocLength);
String jspRootBegin = "<jsp:root "; //NOI18N
int jspRootIndex = text.indexOf(jspRootBegin);
if (jspRootIndex != -1) {
pos = jspRootIndex + jspRootBegin.length();
definition = "xmlns:" + prefix + "=\"" + uri + "\" "; //NOI18N
baseDoc.runAtomic(() -> {
try {
int pos = 0; // FIXME: compute better where to insert tag lib definition?
String definition = "<%@taglib prefix=\"" + prefix + "\" uri=\"" + uri + "\"%>\n"; //NOI18N

//test for .jspx. FIXME: find better way to detect xml syntax?.
FileObject fobj = getFileObject(target);
if (fobj != null && "jspx".equals(fobj.getExt())) {
int baseDocLength = baseDoc.getLength();
String text = baseDoc.getText(0, baseDocLength);
String jspRootBegin = "<jsp:root "; //NOI18N
int jspRootIndex = text.indexOf(jspRootBegin);
if (jspRootIndex != -1) {
pos = jspRootIndex + jspRootBegin.length();
definition = "xmlns:" + prefix + "=\"" + uri + "\" "; //NOI18N
}
}
}

doc.insertString(pos, definition, null);
}
catch (BadLocationException e) {
Exceptions.printStackTrace(e);
}
finally {
baseDoc.atomicUnlock();
}
doc.insertString(pos, definition, null);
} catch (BadLocationException e) {
Exceptions.printStackTrace(e);
}
});
}
}

Expand Down
Loading

0 comments on commit 62d04cf

Please sign in to comment.