Author: vrubezhny
Date: 2008-03-07 15:58:26 -0500 (Fri, 07 Mar 2008)
New Revision: 6791
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-509 intelligent navigation support for seam
variable names
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java 2008-03-07
19:43:55 UTC (rev 6790)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java 2008-03-07
20:58:26 UTC (rev 6791)
@@ -25,7 +25,7 @@
import org.eclipse.search.internal.core.text.PatternConstructor;
import org.eclipse.search.internal.core.text.TextSearchVisitor;
import org.eclipse.search.internal.ui.Messages;
-import org.eclipse.search.internal.ui.SearchMessages;
+//import org.eclipse.search.internal.ui.SearchMessages;
import org.eclipse.search.internal.ui.text.FileMatch;
import org.eclipse.search.internal.ui.text.FileSearchResult;
import org.eclipse.search.internal.ui.text.SearchResultUpdater;
@@ -215,7 +215,9 @@
return Messages.format(SeamUIMessages.SeamSearchQuery_pluralPattern, args);
}
}
- // text search
+/*
+ *
+ // text search
if (isScopeAllFileTypes()) {
// search all file extensions
if (nMatches == 1) {
@@ -232,34 +234,22 @@
}
Object[] args= { searchString, new Integer(nMatches), fScope.getDescription(),
fScope.getFilterDescription() };
return Messages.format(SearchMessages.FileSearchQuery_pluralPatternWithFileExt,
args);
+*/
}
- // file search
+/*
+ *
+ // file search
if (nMatches == 1) {
Object[] args= { fScope.getFilterDescription(), fScope.getDescription() };
return Messages.format(SearchMessages.FileSearchQuery_singularLabel_fileNameSearch,
args);
}
Object[] args= { fScope.getFilterDescription(), new Integer(nMatches),
fScope.getDescription() };
return Messages.format(SearchMessages.FileSearchQuery_pluralPattern_fileNameSearch,
args);
+*/
+ return "";
}
- /**
- * @param result all result are added to this search result
- * @param monitor the progress monitor to use
- * @param file the file to search in
- * @return returns the status of the operation
- */
-/* public IStatus searchInFile(final AbstractTextSearchResult result, final
IProgressMonitor monitor, IFile file) {
- FileTextSearchScope scope= FileTextSearchScope.newSearchScope(new IResource[] { file },
new String[] { "*" }, true); //$NON-NLS-1$
-
- Pattern[] searchPatterns= new Pattern[fVariables == null ? 0 : fVariables.length];
- for (int i = 0; fVariables != null && i < fVariables.length; i++) {
- searchPatterns[i]= getSearchPattern(fVariables[i]);
- }
- SeamSearchResultCollector collector= new SeamSearchResultCollector(result, true);
-
- return SeamSearchEngine.create().search(scope, collector, searchPatterns, monitor);
- }
-*/
+
protected Pattern getSearchPattern(String variableName) {
return PatternConstructor.createPattern(variableName, true, false);
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java 2008-03-07
19:43:55 UTC (rev 6790)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java 2008-03-07
20:58:26 UTC (rev 6791)
@@ -1,12 +1,8 @@
package org.jboss.tools.seam.ui.search;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.search.core.text.TextSearchRequestor;
-import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamDeclaration;
-import org.jboss.tools.seam.core.ISeamElement;
import org.jboss.tools.seam.core.ISeamJavaSourceReference;
public class SeamSearchRequestor extends TextSearchRequestor {
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java 2008-03-07
19:43:55 UTC (rev 6790)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java 2008-03-07
20:58:26 UTC (rev 6791)
@@ -3,13 +3,9 @@
import java.util.Map;
import org.eclipse.core.resources.IFile;
-import org.eclipse.jdt.ui.search.IMatchPresentation;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.search.internal.ui.SearchPluginImages;
-import org.eclipse.search.internal.ui.text.FileSearchQuery;
import org.eclipse.search.ui.ISearchQuery;
-import org.eclipse.search.ui.ISearchResult;
-import org.eclipse.search.ui.ISearchResultListener;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.IEditorMatchAdapter;
import org.eclipse.search.ui.text.IFileMatchAdapter;
@@ -17,7 +13,6 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
-import org.jboss.tools.seam.ui.SeamGuiPlugin;
public class SeamSearchResult extends AbstractTextSearchResult implements
IEditorMatchAdapter, IFileMatchAdapter {
private final Match[] EMPTY_ARR= new Match[0];
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java 2008-03-07
19:43:55 UTC (rev 6790)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java 2008-03-07
20:58:26 UTC (rev 6791)
@@ -33,12 +33,19 @@
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.internal.core.JavaModel;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
import org.eclipse.jdt.ui.text.IJavaPartitions;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.search.core.text.TextSearchScope;
@@ -103,8 +110,13 @@
import org.jboss.tools.seam.internal.core.el.SeamELStringTokenizer;
import org.jboss.tools.seam.internal.core.el.SeamELTokenizer;
import org.jboss.tools.seam.internal.core.el.ElVarSearcher.Var;
+import org.jboss.tools.seam.internal.core.scanner.ScannerException;
+import org.jboss.tools.seam.internal.core.scanner.java.AnnotatedASTNode;
+import org.jboss.tools.seam.internal.core.scanner.java.ResolvedAnnotation;
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
import org.jboss.tools.seam.ui.SeamGuiPlugin;
import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.jboss.tools.seam.ui.text.java.scanner.JavaAnnotationScanner;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -361,15 +373,42 @@
String value = document.get(offset, length);
if(value.indexOf('{')>-1) {
locateMatchesInString(file, value, offset, content);
- } else if (false) {
- // TODO: Insert here the check for named Seam annotations
-
- } else if (true) {
-
}
}
token = scaner.nextToken();
}
+
+ // Search in annotations
+ ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(file);
+ if (compilationUnit == null)
+ return;
+
+ JavaAnnotationScanner annotationScanner = new JavaAnnotationScanner();
+ Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> loadedAnnotations =
null;
+
+ try {
+ annotationScanner.parse((ICompilationUnit)compilationUnit);
+ loadedAnnotations = annotationScanner.getResolvedAnnotations();
+ } catch (ScannerException e) {
+ SeamGuiPlugin.getPluginLog().logError(e);
+ return;
+ }
+ for (ResolvedAnnotation annotation : loadedAnnotations.keySet()) {
+ if (annotationScanner.isAnnotationOfType(annotation,
SeamAnnotations.IN_ANNOTATION_TYPE) ||
+ annotationScanner.isAnnotationOfType(annotation,
SeamAnnotations.OUT_ANNOTATION_TYPE)) {
+ String value = annotationScanner.getAnnotationValue(annotation);
+ if (value == null || value.length() == 0)
+ continue;
+ IRegion valueRegion = annotationScanner.getAnnotationValueRegion(annotation);
+ if (valueRegion == null)
+ continue;
+
+ int length = valueRegion.getLength();
+ int offset = valueRegion.getOffset();
+ String string = "#{" + value + "}";
+ locateMatchesInString(file, string, offset - 2, content);
+ }
+ }
} catch (BadLocationException e) {
SeamGuiPlugin.getDefault().logError(e);
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java 2008-03-07
19:43:55 UTC (rev 6790)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java 2008-03-07
20:58:26 UTC (rev 6791)
@@ -105,11 +105,11 @@
return null;
}
- ResolvedAnnotation a = findAnnotationByValueOffset(loadedAnnotations, offset);
- if (!isAnnotationOfType(a, SeamAnnotations.FACTORY_ANNOTATION_TYPE))
+ ResolvedAnnotation a = annotationScanner.findAnnotationByValueOffset(offset);
+ if (!annotationScanner.isAnnotationOfType(a, SeamAnnotations.FACTORY_ANNOTATION_TYPE))
return null;
- String value = getAnnotationValue(a);
+ String value = annotationScanner.getAnnotationValue(a);
// Look at the annotated method:
// If its return type is not void - the Declaration is the factory itself
@@ -199,102 +199,6 @@
return null;
}
- /*
- * Detects if the type of annotation equals to the selected SeamAnnotations' type
- *
- * @param annotation
- * @param typeName
- *
- * @return
- */
- private boolean isAnnotationOfType(ResolvedAnnotation annotation, String typeName) {
- if (annotation == null || typeName == null)
- return false;
-
- return (typeName.equals(annotation.getType()));
- }
-
- /*
- * Returns the annotation's value text
- *
- * @param annotation
- * @return
- */
- private String getAnnotationValue(ResolvedAnnotation annotation) {
- if (annotation.getAnnotation() instanceof SingleMemberAnnotation) {
- SingleMemberAnnotation sma = (SingleMemberAnnotation)annotation.getAnnotation();
- Object vpd = sma.getStructuralProperty(SingleMemberAnnotation.VALUE_PROPERTY);
- if (vpd instanceof StringLiteral) {
- return ((StringLiteral)vpd).getLiteralValue();
- }
- return vpd.toString();
- } else if (annotation.getAnnotation() instanceof NormalAnnotation) {
- NormalAnnotation na = (NormalAnnotation)annotation.getAnnotation();
- Object vpd = na.getStructuralProperty(NormalAnnotation.VALUES_PROPERTY);
- if (vpd instanceof List) {
- for (Object item : (List)vpd) {
- if (item instanceof ASTNode) {
- ASTNode node = (ASTNode)item;
- if (node.getNodeType() != ASTNode.MEMBER_VALUE_PAIR)
- continue;
- MemberValuePair mvp = (MemberValuePair)node;
- SimpleName name = mvp.getName();
- if (!"value".equals(name.getIdentifier())) {
- continue;
- }
- return ((StringLiteral)mvp.getValue()).getLiteralValue();
- }
- }
- }
- }
-
- return null;
- }
-
- private ResolvedAnnotation findAnnotationByValueOffset(Map<ResolvedAnnotation,
AnnotatedASTNode<ASTNode>> annotations, int offset) {
- if (annotations == null)
- return null;
-
- for (ResolvedAnnotation a : annotations.keySet()) {
- if (a.getAnnotation() instanceof SingleMemberAnnotation) {
- SingleMemberAnnotation sma = (SingleMemberAnnotation)a.getAnnotation();
- Object vpd = sma.getStructuralProperty(SingleMemberAnnotation.VALUE_PROPERTY);
- if (vpd instanceof ASTNode) {
- ASTNode node = (ASTNode)vpd;
- int start = node.getStartPosition();
- int length = node.getLength();
- if (offset >= start && offset < start + length) {
- return a;
- }
- }
- } else if (a.getAnnotation() instanceof NormalAnnotation) {
- NormalAnnotation na = (NormalAnnotation)a.getAnnotation();
- Object vpd = na.getStructuralProperty(NormalAnnotation.VALUES_PROPERTY);
- if (vpd instanceof List) {
- for (Object item : (List)vpd) {
- if (item instanceof ASTNode) {
- ASTNode node = (ASTNode)item;
- if (node.getNodeType() != ASTNode.MEMBER_VALUE_PAIR)
- continue;
- MemberValuePair mvp = (MemberValuePair)node;
- SimpleName name = mvp.getName();
- if (!"value".equals(name.getIdentifier())) {
- continue;
- }
- int start = node.getStartPosition();
- int length = node.getLength();
- if (offset >= start && offset < start + length) {
- return a;
- }
- }
- }
- }
- }
- }
- return null;
- }
-
-
class JavaMemberHyperlink implements IHyperlink {
private final IRegion fRegion;
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java 2008-03-07
19:43:55 UTC (rev 6790)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java 2008-03-07
20:58:26 UTC (rev 6791)
@@ -29,13 +29,17 @@
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.MemberValuePair;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
@@ -226,6 +230,152 @@
}
}
+ public ResolvedAnnotation findAnnotationByValueOffset(int offset) {
+ if (resolvedAnnotations == null)
+ return null;
+
+ for (ResolvedAnnotation a : resolvedAnnotations.keySet()) {
+ if (a.getAnnotation() instanceof SingleMemberAnnotation) {
+ SingleMemberAnnotation sma = (SingleMemberAnnotation)a.getAnnotation();
+ Object vpd = sma.getStructuralProperty(SingleMemberAnnotation.VALUE_PROPERTY);
+ if (vpd instanceof ASTNode) {
+ ASTNode node = (ASTNode)vpd;
+ int start = node.getStartPosition();
+ int length = node.getLength();
+ if (offset >= start && offset < start + length) {
+ return a;
+ }
+ }
+ } else if (a.getAnnotation() instanceof NormalAnnotation) {
+ NormalAnnotation na = (NormalAnnotation)a.getAnnotation();
+ Object vpd = na.getStructuralProperty(NormalAnnotation.VALUES_PROPERTY);
+ if (vpd instanceof List) {
+ for (Object item : (List)vpd) {
+ if (item instanceof ASTNode) {
+ ASTNode node = (ASTNode)item;
+ if (node.getNodeType() != ASTNode.MEMBER_VALUE_PAIR)
+ continue;
+ MemberValuePair mvp = (MemberValuePair)node;
+ SimpleName name = mvp.getName();
+ if (!"value".equals(name.getIdentifier())) {
+ continue;
+ }
+ int start = node.getStartPosition();
+ int length = node.getLength();
+ if (offset >= start && offset < start + length) {
+ return a;
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the annotation's value text
+ *
+ * @param annotation
+ * @return
+ */
+ public String getAnnotationValue(ResolvedAnnotation annotation) {
+ if (annotation.getAnnotation() instanceof SingleMemberAnnotation) {
+ SingleMemberAnnotation sma = (SingleMemberAnnotation)annotation.getAnnotation();
+ Object vpd = sma.getStructuralProperty(SingleMemberAnnotation.VALUE_PROPERTY);
+ if (vpd instanceof StringLiteral) {
+ return ((StringLiteral)vpd).getLiteralValue();
+ }
+ return vpd.toString();
+ } else if (annotation.getAnnotation() instanceof NormalAnnotation) {
+ NormalAnnotation na = (NormalAnnotation)annotation.getAnnotation();
+ Object vpd = na.getStructuralProperty(NormalAnnotation.VALUES_PROPERTY);
+ if (vpd instanceof List) {
+ for (Object item : (List)vpd) {
+ if (item instanceof ASTNode) {
+ ASTNode node = (ASTNode)item;
+ if (node.getNodeType() != ASTNode.MEMBER_VALUE_PAIR)
+ continue;
+ MemberValuePair mvp = (MemberValuePair)node;
+ SimpleName name = mvp.getName();
+ if (!"value".equals(name.getIdentifier())) {
+ continue;
+ }
+ return ((StringLiteral)mvp.getValue()).getLiteralValue();
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the annotation's value region
+ *
+ * @param annotation
+ * @return
+ */
+ public IRegion getAnnotationValueRegion(ResolvedAnnotation annotation) {
+ if (annotation.getAnnotation() instanceof SingleMemberAnnotation) {
+ SingleMemberAnnotation sma = (SingleMemberAnnotation)annotation.getAnnotation();
+ Object vpd = sma.getStructuralProperty(SingleMemberAnnotation.VALUE_PROPERTY);
+ if (vpd instanceof StringLiteral) {
+ StringLiteral sl = (StringLiteral)vpd;
+ return new Region(sl.getStartPosition() + 1, sl.getLength());
+ }
+ if (vpd instanceof ASTNode) {
+ ASTNode astNode = (ASTNode)vpd;
+ return new Region(astNode.getStartPosition(),astNode.getLength());
+ }
+ return null;
+ } else if (annotation.getAnnotation() instanceof NormalAnnotation) {
+ NormalAnnotation na = (NormalAnnotation)annotation.getAnnotation();
+ Object vpd = na.getStructuralProperty(NormalAnnotation.VALUES_PROPERTY);
+ if (vpd instanceof List) {
+ for (Object item : (List)vpd) {
+ if (item instanceof ASTNode) {
+ ASTNode node = (ASTNode)item;
+ if (node.getNodeType() != ASTNode.MEMBER_VALUE_PAIR)
+ continue;
+ MemberValuePair mvp = (MemberValuePair)node;
+ SimpleName name = mvp.getName();
+ if (!"value".equals(name.getIdentifier())) {
+ continue;
+ }
+ Object sValuesObj = mvp.getStructuralProperty(MemberValuePair.VALUE_PROPERTY);
+ if (sValuesObj instanceof StringLiteral) {
+ StringLiteral sl = (StringLiteral)sValuesObj;
+ return new Region(sl.getStartPosition() + 1, sl.getLength());
+ }
+ if (sValuesObj instanceof ASTNode) {
+ ASTNode astNode = (ASTNode)sValuesObj;
+ return new Region(astNode.getStartPosition(),astNode.getLength());
+ }
+ return null;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Detects if the type of annotation equals to the selected SeamAnnotations' type
+ *
+ * @param annotation
+ * @param typeName
+ *
+ * @return
+ */
+ public boolean isAnnotationOfType(ResolvedAnnotation annotation, String typeName) {
+ if (annotation == null || typeName == null)
+ return false;
+
+ return (typeName.equals(annotation.getType()));
+ }
+
static String getResolvedType(IType type, String n) {
String[][] rs;