Author: dgolovin
Date: 2011-08-26 21:10:10 -0400 (Fri, 26 Aug 2011)
New Revision: 34350
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFFuncsELCompletionEngine.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/EnableKBOnProject.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextBuilder.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/LibraryStorage.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/XmlContextImpl.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/NameSpace.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java
Log:
https://issues.jboss.org/browse/JBIDE-1636 Code Review
code cleanup for KB plugin
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFFuncsELCompletionEngine.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFFuncsELCompletionEngine.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFFuncsELCompletionEngine.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -100,7 +100,7 @@
}
ITagLibrary[] libraries = TagLibraryManager.getLibraries(file.getProject());
- if (libraries == null)
+ if (libraries.length==0)
return Collections.emptyList();;
List<IJSFVariable> result = new ArrayList<IJSFVariable>();
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -152,22 +152,13 @@
}
private void saveConvext(ELContext context) {
- if (context != null && context.getResource() != null) {
+ if (context.getResource() != null) {
synchronized (cache) {
cache.put(context.getResource(), context);
}
}
}
- private ELContext removeSavedContext(IFile resource) {
- ELContext removedContext = null;
-
- synchronized (cache) {
- removedContext = cache.remove(resource);
- }
- return removedContext;
- }
-
/**
* Creates a page context for the specified context file
*
@@ -187,7 +178,7 @@
* @return
*/
public static ELContext createPageContext(IFile file, String contextType) {
- return getInstance().createPageContext(file, null, contextType);
+ return getInstance().createPageContext(file, new ArrayList<String>(),
contextType);
}
/**
@@ -196,19 +187,17 @@
* @param file
*/
public void cleanUp(IFile file) {
- if (file == null)
- return;
synchronized (cache) {
- ELContext removedContext = removeSavedContext(file);
+ ELContext removedContext = cache.remove(file);
if (removedContext == null || removedContext.getResource() == null)
return;
-
+ ELContext[] contexts = null;
// Remove all the contexts that are parent to the removed context
- ELContext[] contexts = cache.values().toArray(new ELContext[0]);
+ contexts = cache.values().toArray(new ELContext[cache.values().size()]);
if (contexts != null) {
for (ELContext context : contexts) {
if (isDependencyContext(context, file)) {
- removeSavedContext(file);
+ cache.remove(file);
}
}
}
@@ -221,16 +210,12 @@
* @param file
*/
public void cleanUp(IProject project) {
- if (project == null)
- return;
synchronized (cache) {
// Remove all the contexts that are parent to the removed context
- IFile[] files = cache.keySet().toArray(new IFile[0]);
- if (files != null) {
- for (IFile file : files) {
- if (project.equals(file.getProject())) {
- cleanUp(file);
- }
+ IFile[] files = cache.keySet().toArray(new IFile[cache.size()]);
+ for (IFile file : files) {
+ if (project.equals(file.getProject())) {
+ cleanUp(file);
}
}
}
@@ -243,9 +228,9 @@
*/
public void cleanUp(IResourceDelta delta) {
synchronized (cache) {
- if(cache.size() == 0) return;
- if(!checkDelta(delta)) return;
- processDelta(delta);
+ if(!cache.isEmpty() && checkDelta(delta)) {
+ processDelta(delta);
+ }
}
}
@@ -254,10 +239,7 @@
context.setResource(file);
context.setElResolvers(ELResolverFactoryManager.getInstance().getResolvers(file));
String content = FileUtil.getContentFromEditorOrFile(file);
- int startEl = content.indexOf("#{"); //$NON-NLS-1$
- if(startEl<0)
- startEl = content.indexOf("${"); //$NON-NLS-1$
- if(startEl>-1) {
+ if(content.indexOf('{')>-1 && content.indexOf("#{") >-1
|| content.indexOf("${")>-1 ) { //$NON-NLS-1$
ELParser parser = ELParserUtil.getJbossFactory().createParser();
ELModel model = parser.parse(content);
List<SyntaxError> errors = model.getSyntaxErrors();
@@ -282,7 +264,7 @@
return context;
}
- private ELContext createJavaContext(IFile file) {
+ private static ELContext createJavaContext(IFile file) {
ELContextImpl context = new ELContextImpl();
context.setResource(file);
context.setElResolvers(ELResolverFactoryManager.getInstance().getResolvers(file));
@@ -344,121 +326,68 @@
* @return
*/
private ELContext createPageContext(IFile file, List<String> parents, String
defaultContextType) {
- boolean isContextCachingAllowed = !EclipseUIUtil.isOpenInActiveEditor(file) &&
file != null;
+ boolean isContextCachingAllowed = !EclipseUIUtil.isOpenInActiveEditor(file);
ELContext context = isContextCachingAllowed ? getSavedContext(file) : null;
- if (context != null) {
- return context;
- }
- if (file == null)
- return createContextInstanceOfType(defaultContextType);
-
- IContentType type = IDE.getContentType(file);
- String typeId = (type == null ? null : type.getId());
-
- if(JavaCore.JAVA_SOURCE_CONTENT_TYPE.equalsIgnoreCase(typeId)) {
- context = createJavaContext(file);
- } else if(JAVA_PROPERTIES_CONTENT_TYPE.equalsIgnoreCase(typeId)) {
- context = createPropertiesContext(file);
-// } else if (typeId != null) {
-// context = defaultContextType == null ?
-// createPageContextInstance(typeId) :
-// createContextInstanceOfType(defaultContextType);
-// if (context == null)
-// return null;
-//
-// context.setResource(file);
-// context.setElResolvers(ELResolverFactoryManager.getInstance().getResolvers(file));
-//
-// if (context instanceof JspContextImpl && !(context instanceof
FaceletPageContextImpl)) {
-// // Fill JSP namespaces defined in TLDCMDocumentManager
-// fillJSPNameSpaces((JspContextImpl)context);
-// }
-//
-// // The subsequently called functions may use the file and document
-// // already stored in context for their needs
-// if (context instanceof FaceletPageContextImpl) {
-// IModelManager manager = StructuredModelManager.getModelManager();
-// if(manager == null) {
-// return context;
-// }
-// IStructuredModel model = null;
-// try {
-// model = manager.getModelForRead(file);
-// if (model instanceof IDOMModel) {
-// IDOMModel domModel = (IDOMModel) model;
-// IDOMDocument document = domModel.getDocument();
-// fillContextForChildNodes(document, context, parents);
-// }
-// } catch (CoreException e) {
-// WebKbPlugin.getDefault().logError(e);
-// } catch (IOException e) {
-// WebKbPlugin.getDefault().logError(e);
-// } finally {
-// if (model != null) {
-// model.releaseFromRead();
-// }
-// }
-// }
- } else {
- // ctm = System.currentTimeMillis();
- // System.out.println("Create Context : " + file.getFullPath().toString() +
", Totals: " + cache.size());
- IModelManager manager = StructuredModelManager.getModelManager();
- if(manager == null) {
- // this may happen if plug-in org.eclipse.wst.sse.core
+ if (context == null) {
+ IContentType type = IDE.getContentType(file);
+ String typeId = (type == null ? null : type.getId());
+
+ if(JavaCore.JAVA_SOURCE_CONTENT_TYPE.equalsIgnoreCase(typeId)) {
+ context = createJavaContext(file);
+ } else if(JAVA_PROPERTIES_CONTENT_TYPE.equalsIgnoreCase(typeId)) {
+ context = createPropertiesContext(file);
+ } else {
+ IModelManager manager = StructuredModelManager.getModelManager();
+ // manager==null if plug-in org.eclipse.wst.sse.core
// is stopping or un-installed, that is Eclipse is shutting down.
// there is no need to report it, just stop validation.
- return context;
- }
-
- IStructuredModel model = null;
- try {
- model = manager.getModelForRead(file);
- if (model instanceof IDOMModel) {
- IDOMModel domModel = (IDOMModel) model;
- IDOMDocument document = domModel.getDocument();
-
- context = defaultContextType == null ?
- createPageContextInstance(domModel.getContentTypeIdentifier()) :
- createContextInstanceOfType(defaultContextType);
- if (context == null)
- return null;
-
- context.setResource(file);
- context.setElResolvers(ELResolverFactoryManager.getInstance().getResolvers(file));
-
- if (context instanceof JspContextImpl && !(context instanceof
FaceletPageContextImpl)) {
- // Fill JSP namespaces defined in TLDCMDocumentManager
- fillJSPNameSpaces((JspContextImpl)context);
+ if(manager != null) {
+ IStructuredModel model = null;
+ try {
+ model = manager.getModelForRead(file);
+ if (model instanceof IDOMModel) {
+ IDOMModel domModel = (IDOMModel) model;
+ context = defaultContextType == null ?
+ createPageContextInstance(domModel.getContentTypeIdentifier()) :
+ createContextInstanceOfType(defaultContextType);
+ if (context != null) {
+ IDOMDocument document = domModel.getDocument();
+ context.setResource(file);
+ context.setElResolvers(ELResolverFactoryManager.getInstance().getResolvers(file));
+ if (context instanceof JspContextImpl && !(context instanceof
FaceletPageContextImpl)) {
+ // Fill JSP namespaces defined in TLDCMDocumentManager
+ fillJSPNameSpaces((JspContextImpl)context);
+ }
+ // The subsequently called functions may use the file and document
+ // already stored in context for their needs
+ fillContextForChildNodes(model.getStructuredDocument(), document, context,
parents);
+ }
+ }
+ } catch (CoreException e) {
+ WebKbPlugin.getDefault().logError(e);
+ } catch (IOException e) {
+ WebKbPlugin.getDefault().logError(e);
+ } finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
}
-
- // The subsequently called functions may use the file and document
- // already stored in context for their needs
- fillContextForChildNodes(model.getStructuredDocument(), document, context,
parents);
}
- } catch (CoreException e) {
- WebKbPlugin.getDefault().logError(e);
- } catch (IOException e) {
- WebKbPlugin.getDefault().logError(e);
- } finally {
- if (model != null) {
- model.releaseFromRead();
- }
}
+
+ if (context != null && isContextCachingAllowed) {
+ saveConvext(context);
+ }
}
-
- if (context != null && isContextCachingAllowed) {
- saveConvext(context);
- }
-
return context;
}
- private ELContext createPageContextInstance(String contentType) {
+ private static ELContext createPageContextInstance(String contentType) {
String contextType = IncludeContextBuilder.getContextType(contentType);
return createContextInstanceOfType(contextType);
}
- private ELContext createContextInstanceOfType(String contextType) {
+ private static ELContext createContextInstanceOfType(String contextType) {
if (JSP_PAGE_CONTEXT_TYPE.equals(contextType)) {
return new JspContextImpl();
} else if (FACELETS_PAGE_CONTEXT_TYPE.equals(contextType)) {
@@ -474,7 +403,7 @@
* @param context
*/
@SuppressWarnings({ "unchecked" })
- private void fillJSPNameSpaces(JspContextImpl context) {
+ private static void fillJSPNameSpaces(JspContextImpl context) {
TLDCMDocumentManager manager =
TaglibController.getTLDCMDocumentManager(context.getDocument());
List trackers = (manager == null? null :
manager.getCMDocumentTrackers(context.getDocument().getLength() - 1));
for (int i = 0; trackers != null && i < trackers.size(); i++) {
@@ -542,7 +471,7 @@
}
}
- private void fillVarsForNode (IDOMElement node, ELContextImpl context) {
+ private static void fillVarsForNode (IDOMElement node, ELContextImpl context) {
Var var = ElVarSearcher.findVar(node, ELParserUtil.getJbossFactory());
if (var != null) {
int start = ((IndexedRegion) node).getStartOffset();
@@ -557,7 +486,7 @@
}
}
- private void fillElReferencesForNode(IDocument document, IDOMNode node, XmlContextImpl
context) {
+ private static void fillElReferencesForNode(IDocument document, IDOMNode node,
XmlContextImpl context) {
if(Node.ELEMENT_NODE == node.getNodeType() || Node.TEXT_NODE == node.getNodeType()) {
IStructuredDocumentRegion regionNode = node.getFirstStructuredDocumentRegion();
if (regionNode == null)
@@ -567,38 +496,29 @@
ITextRegion region = regions.get(i);
if(region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE || region.getType()
== DOMRegionContext.XML_CONTENT) {
String text = regionNode.getFullText(region);
- if(text.indexOf("{")>-1) { //$NON-NLS-1$
+ if(text.indexOf('{')>-1 && (text.indexOf("#{") > -1
|| text.indexOf("${") > -1)) { //$NON-NLS-1$
int offset = regionNode.getStartOffset() + region.getStart();
- int startEl = text.indexOf("#{"); //$NON-NLS-1$
- if(startEl==-1) {
- startEl = text.indexOf("${"); //$NON-NLS-1$
- }
- if(startEl>-1) {
- ELParser parser = ELParserUtil.getJbossFactory().createParser();
- ELModel model = parser.parse(text);
- List<ELInstance> is = model.getInstances();
-
- ELReference elReference = new ValidationELReference();
- elReference.setResource(context.getResource());
- elReference.setEl(is);
- elReference.setLength(text.length());
- elReference.setStartPosition(offset);
- try {
- if(Node.TEXT_NODE == node.getNodeType()) {
- if(is.size()==1) {
- elReference.setLineNumber(document.getLineOfOffset(elReference.getStartPossitionOfFirstEL())
+ 1);
- }
- } else {
- elReference.setLineNumber(document.getLineOfOffset(offset) + 1);
+ ELParser parser = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = parser.parse(text);
+ List<ELInstance> is = model.getInstances();
+ ELReference elReference = new ValidationELReference();
+ elReference.setResource(context.getResource());
+ elReference.setEl(is);
+ elReference.setLength(text.length());
+ elReference.setStartPosition(offset);
+ try {
+ if(Node.TEXT_NODE == node.getNodeType()) {
+ if(is.size()==1) {
+ elReference.setLineNumber(document.getLineOfOffset(elReference.getStartPossitionOfFirstEL())
+ 1);
}
- } catch (BadLocationException e) {
- WebKbPlugin.getDefault().logError(e);
+ } else {
+ elReference.setLineNumber(document.getLineOfOffset(offset) + 1);
}
-
- elReference.setSyntaxErrors(model.getSyntaxErrors());
-
- context.addELReference(elReference);
+ } catch (BadLocationException e) {
+ WebKbPlugin.getDefault().logError(e);
}
+ elReference.setSyntaxErrors(model.getSyntaxErrors());
+ context.addELReference(elReference);
}
}
}
@@ -611,66 +531,50 @@
Map<String, List<INameSpace>> nsMap =
context.getNameSpaces(node.getStartOffset());
String[] uris = getUrisByPrefix(nsMap, prefix);
- if (uris != null) {
- for (String uri : uris) {
- if (context instanceof IIncludedContextSupport) {
- String[] includeAttributes = IncludeContextBuilder.getIncludeAttributes(uri,
tagName);
- if (includeAttributes != null) {
- List<String> newParentList = parents == null ? new ArrayList<String>()
: new ArrayList<String>(parents);
- newParentList.add(context.getResource().getFullPath().toString());
-
- for (String attr : includeAttributes) {
- String fileName = node.getAttribute(attr);
- if (fileName == null || fileName.trim().length() == 0)
- continue;
-
+ for (String uri : uris) {
+ if (context instanceof IIncludedContextSupport) {
+ String[] includeAttributes = IncludeContextBuilder.getIncludeAttributes(uri,
tagName);
+ if (includeAttributes.length > 0) {
+ List<String> newParentList = parents == null ? new ArrayList<String>() :
new ArrayList<String>(parents);
+ newParentList.add(context.getResource().getFullPath().toString());
+ for (String attr : includeAttributes) {
+ String fileName = node.getAttribute(attr);
+ if (fileName != null && !fileName.trim().isEmpty()) {
IFile file = getFileFromProject(fileName, context.getResource());
- if (file == null)
- continue;
-
- // Fix for JBIDE-5083 >>>
- if (!checkCycling(parents, file))
- continue;
- // Fix for JBIDE-5083 <<<
-
- ELContext includedContext = createPageContext(file, newParentList, null);
- if (includedContext != null)
- ((IIncludedContextSupport)context).addIncludedContext(includedContext);
+ if (file != null && checkCycling(parents, file)) { // checkCycling is to
fix for JBIDE-5083
+ ELContext includedContext = createPageContext(file, newParentList, null);
+ if (includedContext != null)
+ ((IIncludedContextSupport)context).addIncludedContext(includedContext);
+ }
}
}
}
- if (context instanceof ICSSContainerSupport) {
- if(IncludeContextBuilder.isCSSStyleSheetContainer(uri, tagName)) {
- fillCSSStyleSheetFromElement(node, (ICSSContainerSupport)context, false);
- } else if(IncludeContextBuilder.isJSF2CSSStyleSheetContainer(uri, tagName)) {
- fillCSSStyleSheetFromElement(node, (ICSSContainerSupport)context, true);
- } else {
- String[] cssAttributes = IncludeContextBuilder.getCSSStyleSheetAttributes(uri,
tagName);
- if (cssAttributes != null) {
- for (String attr : cssAttributes) {
- fillCSSStyleSheetFromAttribute(node, attr, (ICSSContainerSupport)context,
false);
- }
- }
- cssAttributes = IncludeContextBuilder.getJSF2CSSStyleSheetAttributes(uri,
tagName);
- if (cssAttributes != null) {
- for (String attr : cssAttributes) {
- fillCSSStyleSheetFromAttribute(node, attr, (ICSSContainerSupport)context, true);
- }
- }
-
+ }
+ if (context instanceof ICSSContainerSupport) {
+ if(IncludeContextBuilder.isCSSStyleSheetContainer(uri, tagName)) {
+ fillCSSStyleSheetFromElement(node, (ICSSContainerSupport)context, false);
+ } else if(IncludeContextBuilder.isJSF2CSSStyleSheetContainer(uri, tagName)) {
+ fillCSSStyleSheetFromElement(node, (ICSSContainerSupport)context, true);
+ } else {
+ String[] cssAttributes = IncludeContextBuilder.getCSSStyleSheetAttributes(uri,
tagName);
+ for (String attr : cssAttributes) {
+ fillCSSStyleSheetFromAttribute(node, attr, (ICSSContainerSupport)context, false);
}
+ cssAttributes = IncludeContextBuilder.getJSF2CSSStyleSheetAttributes(uri, tagName);
+ for (String attr : cssAttributes) {
+ fillCSSStyleSheetFromAttribute(node, attr, (ICSSContainerSupport)context, true);
+ }
+
}
}
}
}
- private boolean checkCycling(List<String> parents, IFile resource) {
+ private static boolean checkCycling(List<String> parents, IFile resource) {
String resourceId = resource.getFullPath().toString();
- if (parents != null) {
- for (String parentId : parents) {
- if (resourceId.equals(parentId))
- return false;
- }
+ for (String parentId : parents) {
+ if (resourceId.equals(parentId))
+ return false;
}
return true;
}
@@ -684,7 +588,7 @@
* @param node
* @param context
*/
- private void fillXMLNamespacesForNode(Element node, XmlContextImpl context) {
+ private static void fillXMLNamespacesForNode(Element node, XmlContextImpl context) {
NamedNodeMap attrs = node.getAttributes();
boolean mainNnIsRedefined = false;
for (int j = 0; attrs != null && j < attrs.getLength(); j++) {
@@ -741,35 +645,33 @@
}
}
- private void fillResourceBundlesForNode(IDOMElement node, JspContextImpl context) {
+ private static void fillResourceBundlesForNode(IDOMElement node, JspContextImpl context)
{
String name = node.getNodeName();
- if (name == null) return;
- if (!name.endsWith("loadBundle")) return; //$NON-NLS-1$
- if (name.indexOf(':') == -1) return;
+ if (name == null || !name.endsWith("loadBundle") || name.indexOf(':')
== -1) //$NON-NLS-1$
+ return;
String prefix = name.substring(0, name.indexOf(':'));
Map<String, List<INameSpace>> ns =
context.getNameSpaces(node.getStartOffset());
if (!containsPrefix(ns, prefix)) return;
NamedNodeMap attributes = node.getAttributes();
- if (attributes == null) return;
String basename = (attributes.getNamedItem("basename") == null ? null :
attributes.getNamedItem("basename").getNodeValue()); //$NON-NLS-1$
//$NON-NLS-2$
String var = (attributes.getNamedItem("var") == null ? null :
attributes.getNamedItem("var").getNodeValue()); //$NON-NLS-1$ //$NON-NLS-2$
- if (basename == null || basename.length() == 0 ||
- var == null || var.length() == 0)
+ if (basename == null || basename.length() == 0 || var == null || var.length() == 0)
return;
context.addResourceBundle(new ResourceBundle(basename, var));
}
- private void fillCSSStyleSheetFromAttribute(IDOMElement node,
+ private static void fillCSSStyleSheetFromAttribute(IDOMElement node,
String attribute, ICSSContainerSupport context, boolean jsf2Source) {
CSSStyleSheetDescriptor descr = getSheetForTagAttribute(node, attribute, jsf2Source);
- if (descr != null)
+ if (descr != null) {
context.addCSSStyleSheetDescriptor(descr);
+ }
}
- private void fillCSSStyleSheetFromElement(IDOMElement node,
+ private static void fillCSSStyleSheetFromElement(IDOMElement node,
ICSSContainerSupport context, boolean jsf2Source) {
CSSStyleSheet sheet = getSheetForTag(node);
if (sheet != null) {
@@ -826,7 +728,7 @@
* @param stylesContainer
* @return
*/
- private CSSStyleSheetDescriptor getSheetForTagAttribute(final Node stylesContainer,
String attribute, boolean jsf2Source) {
+ private static CSSStyleSheetDescriptor getSheetForTagAttribute(final Node
stylesContainer, String attribute, boolean jsf2Source) {
INodeNotifier notifier = (INodeNotifier) stylesContainer;
CSSStyleSheet sheet = null;
String source = null;
@@ -869,7 +771,7 @@
* @param stylesContainer
* @return
*/
- private CSSStyleSheet getSheetForTag(final Node stylesContainer) {
+ private static CSSStyleSheet getSheetForTag(final Node stylesContainer) {
INodeNotifier notifier = (INodeNotifier) stylesContainer;
CSSStyleSheet sheet = null;
@@ -884,7 +786,7 @@
return sheet;
}
- private boolean containsPrefix(Map<String, List<INameSpace>> ns, String
prefix) {
+ private static boolean containsPrefix(Map<String, List<INameSpace>> ns,
String prefix) {
for (List<INameSpace> n: ns.values()) {
for (INameSpace nameSpace : n) {
if(prefix.equals(nameSpace.getPrefix())) return true;
@@ -901,8 +803,9 @@
* @return
*/
public static String[] getUrisByPrefix(Map<String, List<INameSpace>> nsMap,
String prefix) {
- if(nsMap == null || nsMap.isEmpty())
- return null;
+ if(nsMap.isEmpty()) {
+ return new String[0];
+ }
Set<String> uris = new HashSet<String>();
for (List<INameSpace> nsList : nsMap.values()) {
for (INameSpace ns : nsList) {
@@ -971,7 +874,7 @@
IPath projectPath = project.getLocation();
IFile member = null;
- for (int i = 0; resources != null && i < resources.length; i++) {
+ for (int i = 0; i < resources.length; i++) {
IPath runtimePath = resources[i].getRuntimePath();
IPath sourcePath = resources[i].getSourcePath();
@@ -1067,11 +970,11 @@
private static ResourceReference[] sortReferencesByScope(ResourceReference[] references)
{
ResourceReference[] sortedReferences = references.clone();
- Arrays.sort(sortedReferences, new Comparator<ResourceReference>() {
+ Arrays.sort(sortedReferences, new Comparator<ResourceReference>() {
public int compare(ResourceReference r1, ResourceReference r2) {
return r1.getScope() - r2.getScope();
}
- });
+ });
return sortedReferences;
}
@@ -1101,13 +1004,12 @@
@Override
protected boolean isValidAttribute() {
- if (super.isValidAttribute())
- return true;
-
- String href = getElement().getAttribute(hrefAttrName);
- if (href == null || href.length() == 0)
- return false;
- return true;
+ boolean result = true;
+ if (!super.isValidAttribute()) {
+ String href = getElement().getAttribute(hrefAttrName);
+ result = href != null && !href.isEmpty();
+ }
+ return result;
}
/**
@@ -1202,9 +1104,8 @@
cleanUp(event.getDelta());
}
- private boolean checkDelta(IResourceDelta delta) {
+ private static boolean checkDelta(IResourceDelta delta) {
IResource resource = delta.getResource();
- if(resource == null) return false;
if(resource instanceof IWorkspaceRoot) {
IResourceDelta[] d = delta.getAffectedChildren();
return (d.length > 0 && checkDelta(d[0]));
@@ -1213,58 +1114,40 @@
}
private void processDelta(IResourceDelta delta) {
- if(delta == null) return;
- int kind = delta.getKind();
- IResource resource = delta.getResource();
-
- if(resource instanceof IProject &&
- kind == IResourceDelta.REMOVED) {
- cleanUp((IProject)resource);
- } else if (resource instanceof IFile && (
- kind == IResourceDelta.CHANGED ||
- kind == IResourceDelta.ADDED ||
- kind == IResourceDelta.REMOVED ||
- kind == IResourceDelta.CONTENT)) {
- cleanUp((IFile)resource);
+ if(delta!= null) {
+ int kind = delta.getKind();
+ IResource resource = delta.getResource();
+
+ if(resource instanceof IProject &&
+ kind == IResourceDelta.REMOVED) {
+ cleanUp((IProject)resource);
+ } else if (resource instanceof IFile && (
+ kind == IResourceDelta.CHANGED ||
+ kind == IResourceDelta.ADDED ||
+ kind == IResourceDelta.REMOVED ||
+ kind == IResourceDelta.CONTENT)) {
+ cleanUp((IFile)resource);
+ }
+
+ IResourceDelta[] cs = delta.getAffectedChildren();
+ for (int i = 0; i < cs.length; i++) {
+ processDelta(cs[i]);
+ }
}
-
- IResourceDelta[] cs = delta.getAffectedChildren();
- for (int i = 0; cs != null && i < cs.length; i++) {
- processDelta(cs[i]);
- }
- return;
}
- private boolean isDependencyContext(ELContext context, IFile resource) {
+ private static boolean isDependencyContext(ELContext context, IFile resource) {
if (resource.equals(context.getResource())) {
return true;
}
if(context instanceof IIncludedContextSupport) {
List<ELContext> includedContexts =
((IIncludedContextSupport)context).getIncludedContexts();
- if (includedContexts != null) {
- for (ELContext includedContext : includedContexts) {
- if (isDependencyContext(includedContext, resource))
- return true;
- }
+ for (ELContext includedContext : includedContexts) {
+ if (isDependencyContext(includedContext, resource))
+ return true;
}
}
return false;
}
-
- @Override
- protected void finalize() throws Throwable {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- if (workspace != null) workspace.removeResourceChangeListener(this);
-
- synchronized (cache) {
- // Remove all the contexts that are parent to the removed context
- ELContext[] contexts = cache.values().toArray(new ELContext[0]);
- if (contexts != null) {
- for (ELContext context : contexts) {
- removeSavedContext(context.getResource());
- }
- }
- }
- }
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/EnableKBOnProject.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/EnableKBOnProject.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/action/EnableKBOnProject.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -41,8 +41,7 @@
public void run(IMarker marker) {
IResource resource = marker.getResource();
- IProject project = resource instanceof IProject ? (IProject)resource :
- resource != null ? resource.getProject() : null;
+ IProject project = resource instanceof IProject ? (IProject)resource : resource != null
? resource.getProject() : null;
if (project == null)
return;
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextBuilder.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextBuilder.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/include/IncludeContextBuilder.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -27,6 +27,9 @@
*
*/
public class IncludeContextBuilder extends RegistryReader {
+
+ public static final String[] EMPTY = new String[0];
+
// extension point ID
public static final String PL_INCLUDE = "KbIncludeContext"; //$NON-NLS-1$
@@ -129,9 +132,6 @@
* @return
*/
private IncludeContextDefinition getIncludeContextDefinition(String uri) {
- if (fIncludeContextDefs == null || uri == null)
- return null;
-
for (IncludeContextDefinition def : fIncludeContextDefs) {
if (uri.equals(def.getUri())) {
return def;
@@ -214,9 +214,7 @@
if (fCurrentIncludeDefinition != null) {
readElementChildren(element);
}
- return true;
- }
- else if (tag.equals(TAG_TAG)) {
+ } else if (tag.equals(TAG_TAG)) {
processTagElement(element);
// make sure processing of current open on tag resulted in a current definition
@@ -224,13 +222,9 @@
if (fCurrentIncludeDefinition != null) {
readElementChildren(element);
}
- return true;
- }
- else if (tag.equals(TAG_ATTRIBUTE)) {
+ } else if (tag.equals(TAG_ATTRIBUTE)) {
processAttributeElement(element);
- return true;
- }
- else if (tag.equals(TAG_CONTEXTTYPE)) {
+ } else if (tag.equals(TAG_CONTEXTTYPE)) {
processContextTypeElement(element);
// make sure processing of current open on tag resulted in a current definition
@@ -238,13 +232,13 @@
if (fCurrentIncludeDefinition != null) {
readElementChildren(element);
}
- return true;
- }
- else if (tag.equals(TAG_CONTENTTYPE)) {
+ } else if (tag.equals(TAG_CONTENTTYPE)) {
return processContentTypeElement(element);
+ } else {
+ return false;
}
- return false;
+ return true;
}
private void initCache() {
@@ -283,25 +277,27 @@
* @return
*/
public static String[] getIncludeAttributes(String uri, String tagName) {
- if (uri == null)
- return null;
-
List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
- if (defs == null)
- return null;
-
- List<String> attrs = new ArrayList<String>();
-
- for (IncludeContextDefinition def : defs) {
- if (uri.equals(def.getUri())) {
- String[] defAttrs = def.getIncludeTagAttributes(tagName);
- if (defAttrs != null) {
- for (String attr : defAttrs) attrs.add(attr);
+ String[] result = EMPTY;
+ if(!defs.isEmpty()) {
+ List<String> attrs = new ArrayList<String>();
+
+ for (IncludeContextDefinition def : defs) {
+ if (uri.equals(def.getUri())) {
+ String[] defAttrs = def.getIncludeTagAttributes(tagName);
+ if (defAttrs != null) {
+ for (String attr : defAttrs) {
+ attrs.add(attr);
+ }
+ }
}
}
- }
- return attrs.size() == 0 ? null : attrs.toArray(new String[attrs.size()]);
+ if(!attrs.isEmpty()) {
+ result = attrs.toArray(new String[attrs.size()]);
+ }
+ }
+ return result;
}
/**
@@ -311,19 +307,15 @@
* @return
*/
public static String getContextType(String contentType) {
- if (contentType == null)
- return null;
-
- List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
- if (defs == null)
- return null;
-
- for (IncludeContextDefinition def : defs) {
- String contextType = def.getContextType(contentType);
- if (contextType != null)
- return contextType;
+ if (contentType != null) {
+ List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
+ for (IncludeContextDefinition def : defs) {
+ String contextType = def.getContextType(contentType);
+ if (contextType != null)
+ return contextType;
+ }
}
-
+
return null;
}
@@ -335,18 +327,13 @@
* @return
*/
public static boolean isCSSStyleSheetContainer(String uri, String tagName) {
- if (uri == null)
- return false;
-
- List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
- if (defs == null)
- return false;
-
boolean isHolder = false;
- for (IncludeContextDefinition def : defs) {
- if (uri.equals(def.getUri())) {
- String[] defTags = def.getCSSTags();
- if (defTags != null) {
+ if (uri != null) {
+ List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
+
+ for (IncludeContextDefinition def : defs) {
+ if (uri.equals(def.getUri())) {
+ String[] defTags = def.getCSSTags();
for (String tag : defTags) {
if (tagName.equals(tag) || ("".equals(uri) &&
tagName.equalsIgnoreCase(tag))) { //$NON-NLS-1$
isHolder = true;
@@ -360,7 +347,6 @@
}
}
}
-
return isHolder;
}
@@ -372,18 +358,13 @@
* @return
*/
public static boolean isJSF2CSSStyleSheetContainer(String uri, String tagName) {
- if (uri == null)
- return false;
-
- List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
- if (defs == null)
- return false;
-
boolean isHolder = false;
- for (IncludeContextDefinition def : defs) {
- if (uri.equals(def.getUri())) {
- String[] defTags = def.getJSF2CSSTags();
- if (defTags != null) {
+ if (uri != null) {
+ List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
+
+ for (IncludeContextDefinition def : defs) {
+ if (uri.equals(def.getUri())) {
+ String[] defTags = def.getJSF2CSSTags();
for (String tag : defTags) {
if (tagName.equals(tag) || ("".equals(uri) &&
tagName.equalsIgnoreCase(tag))) { //$NON-NLS-1$
isHolder = true;
@@ -397,7 +378,6 @@
}
}
}
-
return isHolder;
}
@@ -409,26 +389,23 @@
* @return
*/
public static String[] getCSSStyleSheetAttributes(String uri, String tagName) {
- if (uri == null)
- return null;
-
+ String[] result = EMPTY;
List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
- if (defs == null)
- return null;
-
- List<String> attrs = new ArrayList<String>();
-
- for (IncludeContextDefinition def : defs) {
- if (uri.equals(def.getUri())) {
- String[] defAttrs = def.getCSSTagAttributes(tagName);
- if (defAttrs != null) {
- for (String attr : defAttrs) attrs.add(attr);
+ if(!defs.isEmpty()) {
+ List<String> attrs = new ArrayList<String>();
+ for (IncludeContextDefinition def : defs) {
+ if (uri.equals(def.getUri())) {
+ String[] defAttrs = def.getCSSTagAttributes(tagName);
+ for (String attr : defAttrs) {
+ attrs.add(attr);
+ }
}
}
+ if(!attrs.isEmpty()) {
+ result = attrs.toArray(new String[attrs.size()]);
+ }
}
-
- return attrs.size() == 0 ? null : attrs.toArray(new String[attrs.size()]);
-
+ return result;
}
/**
@@ -439,25 +416,20 @@
* @return
*/
public static String[] getJSF2CSSStyleSheetAttributes(String uri, String tagName) {
- if (uri == null)
- return null;
-
- List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
- if (defs == null)
- return null;
-
- List<String> attrs = new ArrayList<String>();
-
- for (IncludeContextDefinition def : defs) {
- if (uri.equals(def.getUri())) {
- String[] defAttrs = def.getJSF2CSSTagAttributes(tagName);
- if (defAttrs != null) {
- for (String attr : defAttrs) attrs.add(attr);
+ String[] result = EMPTY;
+ if (uri != null) {
+ List<IncludeContextDefinition> defs =
IncludeContextBuilder.getInstance().getIncludeContextDefinitions();
+ List<String> attrs = new ArrayList<String>();
+ for (IncludeContextDefinition def : defs) {
+ if (uri.equals(def.getUri())) {
+ String[] defAttrs = def.getJSF2CSSTagAttributes(tagName);
+ if (defAttrs != null) {
+ for (String attr : defAttrs) attrs.add(attr);
+ }
}
}
+ result = attrs.toArray(new String[attrs.size()]);
}
-
- return attrs.size() == 0 ? null : attrs.toArray(new String[attrs.size()]);
-
+ return result;
}
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/JspContextImpl.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -32,15 +32,12 @@
* @author Alexey Kazakov
*/
public class JspContextImpl extends XmlContextImpl implements IPageContext,
IIncludedContextSupport, ICSSContainerSupport {
- protected List<IResourceBundle> bundles;
+ protected List<IResourceBundle> bundles = new ArrayList<IResourceBundle>();
- protected List<ELContext> fIncludedContexts = null;
- protected List<CSSStyleSheetDescriptor> fCSSStyleSheetDescriptors = null;
+ protected List<ELContext> fIncludedContexts = new ArrayList<ELContext>();
+ protected List<CSSStyleSheetDescriptor> fCSSStyleSheetDescriptors = new
ArrayList<CSSStyleSheetDescriptor>();;
public void addIncludedContext(ELContext includedContext) {
- if (fIncludedContexts == null) {
- fIncludedContexts = new ArrayList<ELContext>();
- }
fIncludedContexts.add(includedContext);
}
@@ -109,23 +106,18 @@
for (INameSpace ns : nsMap.values()) {
if (ns instanceof INameSpaceExtended) {
ITagLibrary[] libs = ((INameSpaceExtended)ns).getTagLibraries();
- if (libs != null) {
- for(ITagLibrary lib : libs) {
- libraries.add(lib);
- }
+ for(ITagLibrary lib : libs) {
+ libraries.add(lib);
}
}
}
}
- List<ELContext> includedContexts = getIncludedContexts();
- if (includedContexts != null) {
- for (ELContext includedContext : includedContexts) {
- ITagLibrary[] includedLibraries = includedContext instanceof IPageContext ?
((IPageContext)includedContext).getLibraries() : null;
- if (includedLibraries != null) {
- for (ITagLibrary lib : includedLibraries) {
- libraries.add(lib);
- }
+ for (ELContext includedContext : this.fIncludedContexts) {
+ if (includedContext instanceof IPageContext) {
+ ITagLibrary[] includedLibraries = ((IPageContext)includedContext).getLibraries();
+ for (ITagLibrary lib : includedLibraries) {
+ libraries.add(lib);
}
}
}
@@ -139,26 +131,17 @@
* @param bundle
*/
public void addResourceBundle(IResourceBundle bundle) {
- if (bundles == null) {
- bundles = new ArrayList<IResourceBundle>();
- }
bundles.add(bundle);
}
public IResourceBundle[] getResourceBundles() {
Set<IResourceBundle> resourceBundles = new HashSet<IResourceBundle>();
- if (bundles != null) {
- resourceBundles.addAll(bundles);
- }
-
- List<ELContext> includedContexts = getIncludedContexts();
- if (includedContexts != null) {
- for (ELContext includedContext : includedContexts) {
- IResourceBundle[] includedBundles = includedContext instanceof IPageContext ?
((IPageContext)includedContext).getResourceBundles() : null;
- if (includedBundles != null) {
- for (IResourceBundle b : includedBundles) {
- resourceBundles.add(b);
- }
+ resourceBundles.addAll(bundles);
+
+ for (ELContext includedContext : this.fIncludedContexts) {
+ if (includedContext instanceof IPageContext) {
+ for (IResourceBundle b : ((IPageContext)includedContext).getResourceBundles()) {
+ resourceBundles.add(b);
}
}
}
@@ -167,30 +150,17 @@
}
public void addCSSStyleSheetDescriptor(CSSStyleSheetDescriptor cssStyleSheetDescriptor)
{
- if (fCSSStyleSheetDescriptors == null) {
- fCSSStyleSheetDescriptors = new ArrayList<CSSStyleSheetDescriptor>();
- }
fCSSStyleSheetDescriptors.add(cssStyleSheetDescriptor);
}
public List<CSSStyleSheetDescriptor> getCSSStyleSheetDescriptors() {
List<CSSStyleSheetDescriptor> descrs = new
ArrayList<CSSStyleSheetDescriptor>();
- if (fCSSStyleSheetDescriptors != null) {
- for (CSSStyleSheetDescriptor descr : fCSSStyleSheetDescriptors) {
- descrs.add(descr);
- }
- }
+ descrs.addAll(fCSSStyleSheetDescriptors);
- List<ELContext> includedContexts = getIncludedContexts();
- if (includedContexts != null) {
- for (ELContext includedContext : includedContexts) {
- if (includedContext instanceof ICSSContainerSupport) {
- List<CSSStyleSheetDescriptor> includedSheetDescriptors =
((ICSSContainerSupport)includedContext).getCSSStyleSheetDescriptors();
- if (includedSheetDescriptors != null) {
- descrs.addAll(includedSheetDescriptors);
- }
- }
+ for (ELContext includedContext : this.fIncludedContexts) {
+ if (includedContext instanceof ICSSContainerSupport) {
+ descrs.addAll(((ICSSContainerSupport)includedContext).getCSSStyleSheetDescriptors());
}
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -108,7 +108,7 @@
*/
public ITagLibrary[] getTagLibraries(String uri) {
ITagLibrary[] result = libraries.getLibrariesArray(uri);
- if(result == null || result.length == 0) {
+ if(result.length == 0) {
result = StaticLibraries.instance.getLibraries(uri);
}
return result;
@@ -408,7 +408,7 @@
try {
if(!project.hasNature(IKbProject.NATURE_ID)) return;
} catch (CoreException e) {
- //ignore
+ WebKbPlugin.getDefault().logError(e);
}
File file = getStorageFile();
if(file != null) {
@@ -432,19 +432,14 @@
*/
private File getStorageFile() {
WebKbPlugin plugin = WebKbPlugin.getDefault();
- if( plugin != null) {
- //The plug-in instance can be null at shutdown, when the plug-in is stopped.
- IPath path = plugin.getStateLocation();
- File file = new File(path.toFile(), "projects/" + project.getName() +
".xml"); //$NON-NLS-1$ //$NON-NLS-2$
- return file;
- } else {
- return null;
- }
+ //The plug-in instance can be null at shutdown, when the plug-in is stopped.
+ IPath path = plugin.getStateLocation();
+ File file = new File(path.toFile(), "projects/" + project.getName() +
".xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ return file;
}
public void clearStorage() {
- File f = getStorageFile();
- if(f != null && f.isFile()) f.delete();
+ getStorageFile().delete();
}
/*
@@ -810,7 +805,7 @@
List<Change> changes = null;
Set<ITagLibrary> ls = libraries.removePath(source);
- if(ls != null) for (ITagLibrary l: ls) {
+ for (ITagLibrary l: ls) {
changes = Change.addChange(changes, new Change(this, null, l, null));
if(l.getResource() != null && l.getResource().getProject() == project)
modifications++;
}
@@ -827,7 +822,7 @@
* @param cs
*/
public void updateChildPaths(IPath path, Collection<IPath> cs) {
- IPath[] ps = sourcePaths2.keySet().toArray(new IPath[0]);
+ IPath[] ps = sourcePaths2.keySet().toArray(new IPath[sourcePaths2.keySet().size()]);
for (IPath p: ps) {
if(!cs.contains(p) && !p.equals(path) && path.isPrefixOf(p)) {
pathRemoved(p);
@@ -854,7 +849,7 @@
public Map<Object,ITagLibrary> findLibraryDeclarations(IPath source) {
Map<Object,ITagLibrary> map = new HashMap<Object, ITagLibrary>();
Set<ITagLibrary> fs = libraries.getLibrariesBySource(source);
- if(fs != null) for (ITagLibrary c: fs) {
+ for (ITagLibrary c: fs) {
KbObject ci = (KbObject)c;
map.put(ci.getId(), c);
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/LibraryStorage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/LibraryStorage.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/LibraryStorage.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.jst.web.kb.internal;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -24,71 +25,62 @@
*
*/
public class LibraryStorage {
+
+ private static final Set<ITagLibrary> EMPTY_SET = Collections.emptySet();
+ private static final ITagLibrary[] EMPTY_LIB_ARRAY = new ITagLibrary[0];
+
private Set<ITagLibrary> allLibraries = new HashSet<ITagLibrary>();
- private ITagLibrary[] allLibrariesArray = null;
- Map<IPath, Set<ITagLibrary>> librariesBySource = new HashMap<IPath,
Set<ITagLibrary>>();
- Map<String, Set<ITagLibrary>> librariesByUri = new HashMap<String,
Set<ITagLibrary>>();
+ private ITagLibrary[] allLibrariesArray = EMPTY_LIB_ARRAY;
+ private Map<IPath, Set<ITagLibrary>> librariesBySource = new
HashMap<IPath, Set<ITagLibrary>>();
+ private Map<String, Set<ITagLibrary>> librariesByUri = new
HashMap<String, Set<ITagLibrary>>();
private Map<String,ITagLibrary[]> librariesByUriArray = new HashMap<String,
ITagLibrary[]>();
- public void clear() {
- synchronized(allLibraries) {
- allLibraries.clear();
- allLibrariesArray = null;
- }
+ public synchronized void clear() {
+ allLibraries.clear();
+ allLibrariesArray = EMPTY_LIB_ARRAY;
librariesBySource.clear();
- synchronized (librariesByUri) {
- librariesByUri.clear();
- librariesByUriArray.clear();
- }
+ librariesByUri.clear();
+ librariesByUriArray.clear();
}
- public ITagLibrary[] getAllLibrariesArray() {
- if(allLibrariesArray == null) {
- synchronized(allLibraries) {
- allLibrariesArray = allLibraries.toArray(new ITagLibrary[0]);
- }
+ public synchronized ITagLibrary[] getAllLibrariesArray() {
+ if(allLibrariesArray.length == 0) {
+ allLibrariesArray = allLibraries.toArray(new ITagLibrary[allLibraries.size()]);
}
return allLibrariesArray;
}
- private static final ITagLibrary[] EMPTY_LIB_ARRAY = new ITagLibrary[0];
-
- public ITagLibrary[] getLibrariesArray(String uri) {
+ public synchronized ITagLibrary[] getLibrariesArray(String uri) {
ITagLibrary[] result = librariesByUriArray.get(uri);
if(result == null) {
- synchronized(librariesByUri) {
- Set<ITagLibrary> libs = librariesByUri.get(uri);
- if(libs!=null) {
- result = libs.toArray(new ITagLibrary[0]);
- } else {
- result = EMPTY_LIB_ARRAY;
- }
- librariesByUriArray.put(uri, result);
+ Set<ITagLibrary> libs = librariesByUri.get(uri);
+ if(libs!=null) {
+ result = libs.toArray(new ITagLibrary[libs.size()]);
+ } else {
+ result = EMPTY_LIB_ARRAY;
}
+ librariesByUriArray.put(uri, result);
}
return result;
}
- public Set<ITagLibrary> getLibrariesBySource(IPath path) {
- return librariesBySource.get(path);
+ public synchronized Set<ITagLibrary> getLibrariesBySource(IPath path) {
+ Set<ITagLibrary> set = librariesBySource.get(path);
+ return set != null ? set : EMPTY_SET;
}
- public ITagLibrary[] getLibrariesArray(IPath path) {
+ public synchronized ITagLibrary[] getLibrariesArray(IPath path) {
ITagLibrary[] result = EMPTY_LIB_ARRAY;
- synchronized(librariesBySource) {
- Set<ITagLibrary> libs = librariesBySource.get(path);
- if(libs!=null) {
- result = libs.toArray(new ITagLibrary[0]);
- }
+ Set<ITagLibrary> libs = librariesBySource.get(path);
+ if(libs!=null) {
+ result = libs.toArray(new ITagLibrary[0]);
}
return result;
}
- public void addLibrary(ITagLibrary f) {
- synchronized(allLibraries) {
- allLibraries.add(f);
- allLibrariesArray = null;
- }
+ public synchronized void addLibrary(ITagLibrary f) {
+ allLibraries.add(f);
+ allLibrariesArray = EMPTY_LIB_ARRAY;
IPath path = f.getSourcePath();
if(path != null) {
Set<ITagLibrary> fs = librariesBySource.get(path);
@@ -99,22 +91,18 @@
fs.add(f);
}
String uri = f.getURI();
- synchronized (librariesByUri) {
- librariesByUriArray.remove(uri);
- Set<ITagLibrary> ul = librariesByUri.get(uri);
- if (ul == null) {
- ul = new HashSet<ITagLibrary>();
- librariesByUri.put(uri, ul);
- }
- ul.add(f);
+ librariesByUriArray.remove(uri);
+ Set<ITagLibrary> ul = librariesByUri.get(uri);
+ if (ul == null) {
+ ul = new HashSet<ITagLibrary>();
+ librariesByUri.put(uri, ul);
}
+ ul.add(f);
}
- public void removeLibrary(ITagLibrary f) {
- synchronized(allLibraries) {
- allLibraries.remove(f);
- allLibrariesArray = null;
- }
+ public synchronized void removeLibrary(ITagLibrary f) {
+ allLibraries.remove(f);
+ allLibrariesArray = EMPTY_LIB_ARRAY;
IPath path = f.getSourcePath();
if(path != null) {
Set<ITagLibrary> fs = librariesBySource.get(path);
@@ -126,36 +114,35 @@
}
}
String uri = f.getURI();
- synchronized (librariesByUri) {
- Set<ITagLibrary> ul = librariesByUri.get(uri);
- librariesByUriArray.remove(uri);
- if (ul != null) {
- ul.remove(f);
- if (ul.isEmpty()) {
- librariesByUri.remove(uri);
- }
+ Set<ITagLibrary> ul = librariesByUri.get(uri);
+ librariesByUriArray.remove(uri);
+ if (ul != null) {
+ ul.remove(f);
+ if (ul.isEmpty()) {
+ librariesByUri.remove(uri);
}
}
}
- public Set<ITagLibrary> removePath(IPath path) {
+ public synchronized Set<ITagLibrary> removePath(IPath path) {
Set<ITagLibrary> fs = librariesBySource.get(path);
- if(fs == null) return null;
- for (ITagLibrary f: fs) {
- synchronized(allLibraries) {
+ if(fs == null) {
+ fs = EMPTY_SET;
+ } else {
+ for (ITagLibrary f: fs) {
allLibraries.remove(f);
- allLibrariesArray = null;
- }
- synchronized (librariesByUri) {
+ allLibrariesArray = EMPTY_LIB_ARRAY;
Set<ITagLibrary> s = librariesByUri.get(f.getURI());
- if(s != null) s.remove(f);
- if(s != null && s.isEmpty()) {
- librariesByUri.remove(f.getURI());
+ if(s != null) {
+ s.remove(f);
+ if(s.isEmpty()) {
+ librariesByUri.remove(f.getURI());
+ }
}
librariesByUriArray.remove(f.getURI());
}
+ librariesBySource.remove(path);
}
- librariesBySource.remove(path);
return fs;
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/XmlContextImpl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/XmlContextImpl.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/XmlContextImpl.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -112,13 +112,17 @@
* @param name space
*/
public void addNameSpace(IRegion region, INameSpace nameSpace) {
- if (nameSpaces.get(region) == null) {
- Map<String, INameSpace> nameSpaceMap = new HashMap<String, INameSpace>();
+ Map<String, INameSpace> nameSpaceMap = nameSpaces.get(region);
+
+ if (nameSpaceMap == null) {
+ nameSpaceMap = new HashMap<String, INameSpace>();
nameSpaces.put(region, nameSpaceMap);
}
- nameSpaces.get(region).put(nameSpace.getPrefix(), nameSpace); // Fix for JBIDE-5097
+
+ nameSpaceMap.put(nameSpace.getPrefix(), nameSpace); // Fix for JBIDE-5097
+
String uri = nameSpace.getURI();
- if(uri!=null && uri.length()>0) {
+ if(!uri.isEmpty()) {
uris.add(uri);
}
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/AbstractTagLib.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -44,6 +44,7 @@
* Abstract implementation of ITagLibrary
* @author Alexey Kazakov
*/
+
public abstract class AbstractTagLib extends KbObject implements ITagLibrary {
public static String URI = "uri"; //$NON-NLS-1$
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/NameSpace.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/NameSpace.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/taglib/NameSpace.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -33,7 +33,7 @@
* @param prefix
*/
public NameSpace(String uri, String prefix) {
- this(uri, prefix, null);
+ this(uri, prefix, new ITagLibrary[0]);
}
/**
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java 2011-08-27
00:46:51 UTC (rev 34349)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/refactoring/RefactorSearcher.java 2011-08-27
01:10:10 UTC (rev 34350)
@@ -243,7 +243,6 @@
}
protected void searchInCach(IFile file){
- if(file == null) return;
ELResolver[] resolvers = ELResolverFactoryManager.getInstance().getResolvers(file);
ELContext context = PageContextFactory.createPageContext(file);
@@ -252,44 +251,37 @@
return;
ELReference[] references = context.getELReferences();
- resolvers = context.getElResolvers();
- IRelevanceCheck[] checks = getRelevanceChecks(resolvers);
-
+
if(javaElement != null){
+ resolvers = context.getElResolvers();
+ IRelevanceCheck[] checks = getRelevanceChecks(resolvers);
List<MatchArea> areas = new ArrayList<MatchArea>();
for(ELReference reference : references){
int offset = reference.getStartPosition();
for(ELExpression operand : reference.getEl()){
for (int i = 0; i < resolvers.length; i++) {
ELResolver resolver = resolvers[i];
- if (!(resolver instanceof ELCompletionEngine))
+ if (!(resolver instanceof ELCompletionEngine) ||
!checks[i].isRelevant(operand.getText()))
continue;
- if(checks[i] != null && !checks[i].isRelevant(operand.getText()))
- continue;
ELResolution resolution = resolver.resolve(context, operand, offset);
- if(resolution == null)
- continue;
-
- List<ELSegment> segments =
resolution.findSegmentsByJavaElement(javaElement);
-
- if(segments == null)
- continue;
-
- for(ELSegment segment : segments){
- int o = offset+segment.getSourceReference().getStartPosition();
- int l = segment.getSourceReference().getLength();
-
- if(!contains(areas, o, l)){
- match(file, o, l);
- areas.add(new MatchArea(o, l));
+ if(resolution != null) {
+ List<ELSegment> segments =
resolution.findSegmentsByJavaElement(javaElement);
+ for(ELSegment segment : segments){
+ int o = offset+segment.getSourceReference().getStartPosition();
+ int l = segment.getSourceReference().getLength();
+
+ if(!contains(areas, o, l)){
+ match(file, o, l);
+ areas.add(new MatchArea(o, l));
+ }
}
}
}
}
}
- }else{
+ } else {
for(ELReference reference : references){
int offset = reference.getStartPosition();
ELExpression[] expressions = reference.getEl();
@@ -324,7 +316,6 @@
}
protected IRelevanceCheck[] getRelevanceChecks(ELResolver[] resolvers) {
- if(resolvers == null) return new IRelevanceCheck[0];
IRelevanceCheck[] checks = new IRelevanceCheck[resolvers.length];
for (int i = 0; i < checks.length; i++) {
checks[i] = resolvers[i].createRelevanceCheck(javaElement);