Basic test coverage for content assist.
diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/BeanSuffixHyperlink.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/BeanSuffixHyperlink.java
index ed33e59..5114704 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/BeanSuffixHyperlink.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/BeanSuffixHyperlink.java
@@ -20,25 +20,17 @@
* on the link, since determining takes too long.
*/
class BeanSuffixHyperlink implements IHyperlink {
- private final IRegion fRegion;
- private final ISymbol symbol;
+ private final IRegion _fRegion;
+ private final ISymbol _symbol;
- /**Creates a BeanSuffixHyperlink for a bean property symbol
+ /**
+ * Creates a BeanSuffixHyperlink for a symbol
* @param region - the region of the hyperlink
* @param symbol
*/
- public BeanSuffixHyperlink(final IRegion region, final IBeanPropertySymbol symbol) {
- fRegion = region;
- this.symbol = symbol;
- }
-
- /**Creates a BeanSuffixHyperlink for a bean method symbol
- * @param region - the region of the hyperlink
- * @param symbol
- */
- public BeanSuffixHyperlink(final IRegion region, final IBeanMethodSymbol symbol) {
- fRegion = region;
- this.symbol = symbol;
+ public BeanSuffixHyperlink(final IRegion region, final ISymbol symbol) {
+ _fRegion = region;
+ _symbol = symbol;
}
/*
@@ -47,7 +39,7 @@
* @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkRegion()
*/
public IRegion getHyperlinkRegion() {
- return fRegion;
+ return _fRegion;
}
/*
@@ -74,7 +66,7 @@
* @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
*/
public void open() {
- final IJavaElement element = determineJavaElement(symbol);
+ final IJavaElement element = determineJavaElement(_symbol);
if (element != null) {
try {
final IEditorPart editor = JavaUI.openInEditor(element);
@@ -89,11 +81,11 @@
}
private IJavaElement determineJavaElement(final ISymbol symbol2) {
- if (symbol instanceof IBeanPropertySymbol) {
- return determinePropertyElement((IBeanPropertySymbol) symbol);
+ if (_symbol instanceof IBeanPropertySymbol) {
+ return determinePropertyElement((IBeanPropertySymbol) _symbol);
}
- if (symbol instanceof IBeanMethodSymbol) {
- return JavaUtil.findCorrespondingMethod((IBeanMethodSymbol) symbol);
+ if (_symbol instanceof IBeanMethodSymbol) {
+ return JavaUtil.findCorrespondingMethod((IBeanMethodSymbol) _symbol);
}
return null;
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/ELHyperlinkDetector.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/ELHyperlinkDetector.java
index 0444b49..1dad1a1 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/ELHyperlinkDetector.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/ELHyperlinkDetector.java
@@ -14,51 +14,77 @@
import org.eclipse.jst.jsf.context.symbol.ISymbol;
import org.eclipse.jst.jsf.core.internal.contentassist.el.SymbolInfo;
-/** This HyperlinkDetector creates hyperlinks for symbols in JSF EL expressions inside jsp files.
+/**
+ * This HyperlinkDetector creates hyperlinks for symbols in JSF EL expressions
+ * inside jsp files.
*/
public class ELHyperlinkDetector extends AbstractHyperlinkDetector {
- public IHyperlink[] detectHyperlinks(final ITextViewer textViewer, final IRegion region, final boolean canShowMultipleHyperlinks) {
- final IStructuredDocumentContext context = IStructuredDocumentContextFactory.INSTANCE.getContext(textViewer,
- region.getOffset());
- final Region elRegion = JSPSourceUtil.findELRegion(context);
- if (elRegion != null) {
- final SymbolInfo symbolInfo = JSPSourceUtil.determineSymbolInfo(context, elRegion, region.getOffset());
- if (symbolInfo != null) {
- IHyperlink link = null;
- final Region linkRegion = new Region(symbolInfo.getRelativeRegion().getOffset() + elRegion.getOffset(), symbolInfo.getRelativeRegion().getLength());
- final ISymbol symbol = symbolInfo.getSymbol();
- if (symbol instanceof IBeanInstanceSymbol) {
- link = createBeanInstanceLink(linkRegion, (IBeanInstanceSymbol) symbol);
- } else if (symbol instanceof IBeanPropertySymbol) {
- link = createBeanPropertyLink(linkRegion, (IBeanPropertySymbol) symbol);
- } else if (symbol instanceof IBeanMethodSymbol) {
- link = createMethodLink(linkRegion, (IBeanMethodSymbol) symbol);
- }
- if (link != null) {
- return new IHyperlink[]{link};
- }
- }
- }
- return null;
- }
+ public final IHyperlink[] detectHyperlinks(final ITextViewer textViewer,
+ final IRegion region, final boolean canShowMultipleHyperlinks) {
+ final IStructuredDocumentContext context = IStructuredDocumentContextFactory.INSTANCE
+ .getContext(textViewer, region.getOffset());
+ return detectHyperlinks(context, region);
+ }
- private IHyperlink createBeanInstanceLink(final Region region, final IBeanInstanceSymbol symbol) {
- if (symbol.isTypeResolved()) {
- final IType type = symbol.getJavaTypeDescriptor().getType();
- return new JavaElementHyperlink(region, type);
- }
- return null;
- }
+ /**
+ * Broken out for testing.
+ * @param context
+ * @param region
+ * @return the hyperlinks
+ */
+ protected IHyperlink[] detectHyperlinks(
+ final IStructuredDocumentContext context, final IRegion region) {
+ final Region elRegion = JSPSourceUtil.findELRegion(context);
+ if (elRegion != null) {
+ final SymbolInfo symbolInfo = JSPSourceUtil.determineSymbolInfo(
+ context, elRegion, region.getOffset());
+ if (symbolInfo != null) {
+ IHyperlink link = null;
+ final Region linkRegion = new Region(symbolInfo
+ .getRelativeRegion().getOffset()
+ + elRegion.getOffset(), symbolInfo.getRelativeRegion()
+ .getLength());
+ final ISymbol symbol = symbolInfo.getSymbol();
+ if (symbol instanceof IBeanInstanceSymbol) {
+ link = createBeanInstanceLink(linkRegion,
+ (IBeanInstanceSymbol) symbol);
+ } else if (symbol instanceof IBeanPropertySymbol) {
+ link = createBeanPropertyLink(linkRegion,
+ (IBeanPropertySymbol) symbol);
+ } else if (symbol instanceof IBeanMethodSymbol) {
+ link = createMethodLink(linkRegion,
+ (IBeanMethodSymbol) symbol);
+ }
+ if (link != null) {
+ return new IHyperlink[] { link };
+ }
+ }
+ }
+ return null;
+ }
- private IHyperlink createBeanPropertyLink(final Region region, final IBeanPropertySymbol symbol) {
- //defer calculation of access method until user click on link (takes too long otherwise):
- return new BeanSuffixHyperlink(region, symbol);
- }
+ private IHyperlink createBeanInstanceLink(final Region region,
+ final IBeanInstanceSymbol symbol) {
+ if (symbol.isTypeResolved()) {
+ final IType type = symbol.getJavaTypeDescriptor().getType();
+ return new JavaElementHyperlink(region, type);
+ }
+ return null;
+ }
- private IHyperlink createMethodLink(final Region region, final IBeanMethodSymbol symbol) {
- //defer calculation of access method until user click on link (takes too long otherwise):
- return new BeanSuffixHyperlink(region, symbol);
- }
+ private IHyperlink createBeanPropertyLink(final Region region,
+ final IBeanPropertySymbol symbol) {
+ // defer calculation of access method until user click on link (takes
+ // too long otherwise):
+ return new BeanSuffixHyperlink(region, symbol);
+ }
+
+ private IHyperlink createMethodLink(final Region region,
+ final IBeanMethodSymbol symbol) {
+ // defer calculation of access method until user click on link (takes
+ // too long otherwise):
+ return new BeanSuffixHyperlink(region, symbol);
+ }
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/JSFELHover.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/JSFELHover.java
index f83dbe6..70c47f3 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/JSFELHover.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/JSFELHover.java
@@ -10,13 +10,13 @@
import org.eclipse.jst.jsf.context.symbol.ISymbol;
import org.eclipse.jst.jsf.core.internal.contentassist.el.SymbolInfo;
-/** This class creates hovers for ISymbols in an el expression that have a detailedDescription.
+/** This class creates hovers for ISymbols in an el expression that have a detailedDescription.
*/
public class JSFELHover implements ITextHover {
private ISymbol hoveredSymbol = null;
- public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+ public String getHoverInfo(final ITextViewer textViewer, final IRegion hoverRegion) {
// hoveredSymbol set by getHoverRegion, which is called first
if (hoveredSymbol instanceof IDescribedInDetail) {
return ((IDescribedInDetail) hoveredSymbol).getDetailedDescription();
@@ -24,23 +24,23 @@
return null;
}
- public IRegion getHoverRegion(ITextViewer textViewer, int documentPosition) {
+ public IRegion getHoverRegion(final ITextViewer textViewer, final int documentPosition) {
final IStructuredDocumentContext context = IStructuredDocumentContextFactory.INSTANCE.getContext(textViewer,
documentPosition);
hoveredSymbol = null;
- Region elRegion = JSPSourceUtil.findELRegion(context);
+ final Region elRegion = JSPSourceUtil.findELRegion(context);
if (elRegion != null) {
- SymbolInfo symbolInfo = JSPSourceUtil.determineSymbolInfo(context, elRegion, documentPosition);
+ final SymbolInfo symbolInfo = JSPSourceUtil.determineSymbolInfo(context, elRegion, documentPosition);
if (symbolInfo == null) {
return null;
}
final Region relativeRegion = symbolInfo.getRelativeRegion();
- Region symbolRegion = new Region(elRegion.getOffset()
+ final Region symbolRegion = new Region(elRegion.getOffset()
+ relativeRegion.getOffset(), relativeRegion.getLength());
hoveredSymbol = symbolInfo.getSymbol();
return symbolRegion;
}
return null;
}
-
+
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/JSPSourceUtil.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/JSPSourceUtil.java
index 26db980..48de166 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/JSPSourceUtil.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jspeditor/JSPSourceUtil.java
@@ -23,9 +23,9 @@
* @param context - the IStructuredDocumentContext
* @return region of el expression, null if context doesn't point to an el expression
*/
- public static Region findELRegion(IStructuredDocumentContext context) {
+ public static Region findELRegion(final IStructuredDocumentContext context) {
if (context != null) {
- ITextRegionContextResolver resolver = IStructuredDocumentContextResolverFactory.INSTANCE
+ final ITextRegionContextResolver resolver = IStructuredDocumentContextResolverFactory.INSTANCE
.getTextRegionResolver(context);
if (resolver != null) {
@@ -45,22 +45,22 @@
return null;
}
- /**Determines symbol and symbol region at a given document position
+ /**Determines symbol and symbol region at a given document position
* @param context - the IStructuredDocumentContext
* @param elRegion - the region of the el expression to consider
* @param documentPosition - the document position to get the symbol for
* @return SymbolInfo
*/
- public static SymbolInfo determineSymbolInfo(IStructuredDocumentContext context, Region elRegion,
- int documentPosition) {
+ public static SymbolInfo determineSymbolInfo(final IStructuredDocumentContext context, final Region elRegion,
+ final int documentPosition) {
if (context != null && elRegion != null) {
try {
String elText;
elText = context.getStructuredDocument().get(elRegion.getOffset(), elRegion.getLength());
- SymbolInfo symbolInfo = ContentAssistParser.getSymbolInfo(context, documentPosition
+ final SymbolInfo symbolInfo = ContentAssistParser.getSymbolInfo(context, documentPosition
- elRegion.getOffset() + 1, elText);
return symbolInfo;
- } catch (BadLocationException e) {
+ } catch (final BadLocationException e) {
// well, so we simply have no symbol, no reason to worry (or
// log...)
return null;