JBoss Tools SVN: r44480 - trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2012-10-12 09:33:43 -0400 (Fri, 12 Oct 2012)
New Revision: 44480
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java
Log:
Fixed - JBIDE-12765 - Unable to parse web.xml
SAXException are logged in DEBUG level, so not reported in the Error Log
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java 2012-10-12 13:19:09 UTC (rev 44479)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/internal/utils/WtpUtils.java 2012-10-12 13:33:43 UTC (rev 44480)
@@ -1,7 +1,6 @@
package org.jboss.tools.ws.jaxrs.core.internal.utils;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -73,7 +72,7 @@
* @throws CoreException
*/
public static String getApplicationPath(IResource webxmlResource, String applicationTypeName) throws CoreException {
- if(webxmlResource == null) {
+ if (webxmlResource == null) {
return null;
}
if (!webxmlResource.exists()) {
@@ -86,10 +85,12 @@
}
try {
- final String expression = "//servlet-mapping[servlet-name=\"" + applicationTypeName + "\"]/url-pattern/text()";
+ final String expression = "//servlet-mapping[servlet-name=\"" + applicationTypeName
+ + "\"]/url-pattern/text()";
final Node urlPattern = evaluateXPathExpression(webxmlResource, expression);
if (urlPattern != null) {
- Logger.debug("Found matching url-pattern: {} for class {}", urlPattern.getTextContent(), applicationTypeName);
+ Logger.debug("Found matching url-pattern: {} for class {}", urlPattern.getTextContent(),
+ applicationTypeName);
return urlPattern.getTextContent();
}
} catch (Exception e) {
@@ -103,8 +104,8 @@
}
/**
- * Attempts to find the <strong>node range</strong> for the applicationPath configured in the application's web deployment description. The
- * applicationPath is expected to be configured as below: <code>
+ * Attempts to find the <strong>node range</strong> for the applicationPath configured in the application's web
+ * deployment description. The applicationPath is expected to be configured as below: <code>
* <servlet-mapping>
* <servlet-name>com.acme.MyApplication</servlet-name>
* <url-pattern>/hello/*</url-pattern>
@@ -122,8 +123,9 @@
* @return the source range or null if it is not configured.
* @throws CoreException
*/
- public static ISourceRange getApplicationPathLocation(final IResource webxmlResource, final String applicationTypeName) throws CoreException {
- if(webxmlResource == null) {
+ public static ISourceRange getApplicationPathLocation(final IResource webxmlResource,
+ final String applicationTypeName) throws CoreException {
+ if (webxmlResource == null) {
return null;
}
if (!webxmlResource.exists()) {
@@ -132,7 +134,7 @@
}
try {
final String expression = "//servlet-mapping[servlet-name=\"" + applicationTypeName + "\"]";
- final Node servletMappingNode = evaluateXPathExpression(webxmlResource, expression);
+ final Node servletMappingNode = evaluateXPathExpression(webxmlResource, expression);
if (servletMappingNode != null) {
StringWriter writer = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
@@ -140,11 +142,11 @@
transformer.transform(new DOMSource(servletMappingNode), new StreamResult(writer));
String servletMappingXml = writer.toString();
Logger.debug("Found matching servlet-mapping: {}", servletMappingXml);
- final InputStream contents = ((IFile)webxmlResource).getContents();
+ final InputStream contents = ((IFile) webxmlResource).getContents();
int offset = findLocation(contents, servletMappingXml);
- if(offset != -1) {
+ if (offset != -1) {
int length = servletMappingXml.length();
- return new SourceRange(offset-length+1, length);
+ return new SourceRange(offset - length + 1, length);
}
return new SourceRange(0, 0);
}
@@ -157,20 +159,21 @@
webxmlResource.getProjectRelativePath());
return null;
}
-
+
/**
* Return the searchString location in the input source
+ *
* @param reader
* @param searchString
* @return the matching location or -1 if not found
* @throws IOException
*/
private static int findLocation(InputStream stream, String searchString) throws IOException {
- char[] buffer = new char[1024];
- int location = -1;
- int numCharsRead;
- int count = 0;
- Reader reader = null;
+ char[] buffer = new char[1024];
+ int location = -1;
+ int numCharsRead;
+ int count = 0;
+ Reader reader = null;
try {
reader = new InputStreamReader(stream);
// reading the stream
@@ -200,37 +203,51 @@
}
}
-
/**
+ * Evaluate the (XPath) expression on the given resource.
+ *
* @param webxmlResource
* @param applicationTypeName
- * @return
- * @throws ParserConfigurationException
- * @throws FileNotFoundException
- * @throws SAXException
- * @throws IOException
- * @throws XPathExpressionException
+ * @return the xpath expression evalutation or null if an error occurred
*/
- private static Node evaluateXPathExpression(final IResource webxmlResource, final String expression)
- throws ParserConfigurationException, FileNotFoundException, SAXException, IOException,
- XPathExpressionException {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(false); // never forget this!
- dbf.setValidating(false);
- dbf.setFeature("http://xml.org/sax/features/namespaces", false);
- dbf.setFeature("http://xml.org/sax/features/validation", false);
- dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
- dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
- DocumentBuilder builder = dbf.newDocumentBuilder();
- final FileInputStream fileInputStream = new FileInputStream(webxmlResource.getLocation().toFile());
- InputSource inputSource = new InputSource(fileInputStream);
- Document doc = builder.parse(inputSource);
- XPath xpath = XPathFactory.newInstance().newXPath();
- XPathExpression expr = xpath.compile(expression);
- Node servletMapping = (Node) expr.evaluate(doc, XPathConstants.NODE);
- return servletMapping;
+ private static Node evaluateXPathExpression(final IResource webxmlResource, final String expression) {
+ FileInputStream fileInputStream = null;
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(false); // never forget this!
+ dbf.setValidating(false);
+ dbf.setFeature("http://xml.org/sax/features/namespaces", false);
+ dbf.setFeature("http://xml.org/sax/features/validation", false);
+ dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
+ dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ fileInputStream = new FileInputStream(webxmlResource.getLocation().toFile());
+ InputSource inputSource = new InputSource(fileInputStream);
+ Document doc = builder.parse(inputSource);
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ XPathExpression expr = xpath.compile(expression);
+ Node servletMapping = (Node) expr.evaluate(doc, XPathConstants.NODE);
+ return servletMapping;
+ } catch (ParserConfigurationException e) {
+ Logger.error("Error while analyzing web deployment descriptor", e);
+ } catch (SAXException e) {
+ // if xml file is malformed, there should already be some error markers, so no need to fill the error log.
+ Logger.debug("Error while analyzing web deployment descriptor", e);
+ } catch (IOException e) {
+ Logger.error("Error while analyzing web deployment descriptor", e);
+ } catch (XPathExpressionException e) {
+ Logger.error("Error while analyzing web deployment descriptor", e);
+ } finally {
+ if (fileInputStream != null) {
+ try {
+ fileInputStream.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ return null;
}
-
+
/**
* Indicates if the given resource is the web deployment descriptor (or not).
*
12 years, 3 months
JBoss Tools SVN: r44479 - trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2012-10-12 09:19:09 -0400 (Fri, 12 Oct 2012)
New Revision: 44479
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
Log:
Fixed - JBIDE-12814 - "Could not resolve bindings form method" when editing REST service
Keeping the message but downgrading to "DEBUG" level so that they are not seen by the user.
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2012-10-12 12:54:59 UTC (rev 44478)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaMethodSignaturesVisitor.java 2012-10-12 13:19:09 UTC (rev 44479)
@@ -78,7 +78,7 @@
final IMethodBinding methodBinding = declaration.resolveBinding();
// sometimes, the binding cannot be resolved
if (methodBinding == null) {
- Logger.warn("Could not resolve bindings form method " + method.getElementName());
+ Logger.debug("Could not resolve bindings form method " + method.getElementName());
} else {
final IType returnedType = getReturnType(methodBinding);
//.getReturnType().getJavaElement() : null;
12 years, 3 months
JBoss Tools SVN: r44478 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2012-10-12 08:54:59 -0400 (Fri, 12 Oct 2012)
New Revision: 44478
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java
Log:
renamed variable user->connection
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java 2012-10-12 12:54:31 UTC (rev 44477)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java 2012-10-12 12:54:59 UTC (rev 44478)
@@ -23,10 +23,6 @@
public ConnectToOpenShiftWizardModel() {
}
- /**
- * Constructor
- * @param connection the user to use to connect to OpenShift.
- */
public ConnectToOpenShiftWizardModel(final Connection connection) {
this.connection = connection;
}
12 years, 3 months
JBoss Tools SVN: r44477 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2012-10-12 08:54:31 -0400 (Fri, 12 Oct 2012)
New Revision: 44477
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java
Log:
renamed variable user->connection
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java 2012-10-12 12:52:56 UTC (rev 44476)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java 2012-10-12 12:54:31 UTC (rev 44477)
@@ -25,10 +25,10 @@
/**
* Constructor
- * @param user the user to use to connect to OpenShift.
+ * @param connection the user to use to connect to OpenShift.
*/
- public ConnectToOpenShiftWizardModel(final Connection user) {
- this.connection = user;
+ public ConnectToOpenShiftWizardModel(final Connection connection) {
+ this.connection = connection;
}
@Override
12 years, 3 months
JBoss Tools SVN: r44476 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2012-10-12 08:52:56 -0400 (Fri, 12 Oct 2012)
New Revision: 44476
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java
Log:
renamed variable user->connection
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java 2012-10-12 12:51:42 UTC (rev 44475)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ConnectToOpenShiftWizardModel.java 2012-10-12 12:52:56 UTC (rev 44476)
@@ -18,7 +18,7 @@
*/
public class ConnectToOpenShiftWizardModel implements IConnectionAwareModel {
- protected Connection user;
+ protected Connection connection;
public ConnectToOpenShiftWizardModel() {
}
@@ -28,18 +28,18 @@
* @param user the user to use to connect to OpenShift.
*/
public ConnectToOpenShiftWizardModel(final Connection user) {
- this.user = user;
+ this.connection = user;
}
@Override
public Connection getConnection() {
- return user == null ? ConnectionsModel.getDefault().getRecentConnection() : user;
+ return connection == null ? ConnectionsModel.getDefault().getRecentConnection() : connection;
}
@Override
- public Connection setConnection(Connection user) {
- this.user = user;
- return user;
+ public Connection setConnection(Connection connection) {
+ this.connection = connection;
+ return connection;
}
@Override
12 years, 3 months
JBoss Tools SVN: r44475 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2012-10-12 08:51:42 -0400 (Fri, 12 Oct 2012)
New Revision: 44475
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/CredentialsPrompter.java
Log:
renamed variable user->connection
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/CredentialsPrompter.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/CredentialsPrompter.java 2012-10-12 12:20:35 UTC (rev 44474)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/CredentialsPrompter.java 2012-10-12 12:51:42 UTC (rev 44475)
@@ -25,7 +25,7 @@
public class CredentialsPrompter implements ICredentialsPrompter {
@Override
- public void promptAndAuthenticate(final Connection user) {
+ public void promptAndAuthenticate(final Connection connection) {
Display.getDefault().syncExec(
new Runnable() {
public void run() {
@@ -36,7 +36,7 @@
}
final ConnectToOpenShiftWizard connectToOpenShiftWizard =
- new ConnectToOpenShiftWizard(user);
+ new ConnectToOpenShiftWizard(connection);
WizardUtils.openWizardDialog(connectToOpenShiftWizard, shell);
}
});
12 years, 3 months
JBoss Tools SVN: r44474 - trunk/jst/tests/org.jboss.tools.jst.css.test/src/org/jboss/tools/jst/css/test.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2012-10-12 08:20:35 -0400 (Fri, 12 Oct 2012)
New Revision: 44474
Modified:
trunk/jst/tests/org.jboss.tools.jst.css.test/src/org/jboss/tools/jst/css/test/CSSAllTests.java
Log:
https://issues.jboss.org/browse/JBIDE-12656 : org.jboss.tools.jst.css.test.jbide.SelectionLosingByPropertySheet_JBIDE4791 failure
- commented failing test
Modified: trunk/jst/tests/org.jboss.tools.jst.css.test/src/org/jboss/tools/jst/css/test/CSSAllTests.java
===================================================================
--- trunk/jst/tests/org.jboss.tools.jst.css.test/src/org/jboss/tools/jst/css/test/CSSAllTests.java 2012-10-12 11:56:48 UTC (rev 44473)
+++ trunk/jst/tests/org.jboss.tools.jst.css.test/src/org/jboss/tools/jst/css/test/CSSAllTests.java 2012-10-12 12:20:35 UTC (rev 44474)
@@ -39,7 +39,11 @@
// $JUnit-BEGIN$
suite.addTestSuite(CSSViewTest.class);
suite.addTestSuite(InputFractionalValueTest_JBIDE4790.class);
- suite.addTestSuite(SelectionLosingByPropertySheet_JBIDE4791.class);
+
+ /* yradtsevich: Commented because it is randomly failing https://issues.jboss.org/browse/JBIDE-12656.
+ * Please uncomment when JBIDE-4791 will be fixed. */
+ // suite.addTestSuite(SelectionLosingByPropertySheet_JBIDE4791.class);
+
suite.addTestSuite(ExtendingCSSViewTest_JBIDE4850.class);
suite.addTestSuite(NotCompletedCSS_JBIDE4677.class);
suite.addTestSuite(IncorrectPageAfterSelectionTest_JBIDE4849.class);
12 years, 3 months
JBoss Tools SVN: r44473 - trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2012-10-12 07:56:48 -0400 (Fri, 12 Oct 2012)
New Revision: 44473
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg
Log:
https://issues.jboss.org/browse/JBIDE-12623 : BrowserSim: create iPhone 5 skin
Modified: trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg 2012-10-12 11:46:13 UTC (rev 44472)
+++ trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/resources/config/devices.cfg 2012-10-12 11:56:48 UTC (rev 44473)
@@ -6,6 +6,7 @@
Apple iPad 2 768 1024 1 Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5 iPhone 4
Apple iPhone 3 320 480 1 Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7 iPhone 3
Apple iPhone 4 640 960 2 Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7 iPhone 4
+Apple iPhone 5 640 1136 2 Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25 iPhone 4
RIM BlackBerry Bold Touch 9900 640 480 1 Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.246 Mobile Safari/534.1+ iPhone 3
Samsung Galaxy S 480 800 1.5 Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; GT-I9000 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 iPhone 3
Samsung Galaxy S II 480 800 1.5 Mozilla/5.0 (Linux; U; Android 2.3; en-us; GT-I9100 Build/GRH78) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 iPhone 3
12 years, 3 months
JBoss Tools SVN: r44472 - in trunk/ws: plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: xcoulon
Date: 2012-10-12 07:46:13 -0400 (Fri, 12 Oct 2012)
New Revision: 44472
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/RangeUtils.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationLocator.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java
trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java
Log:
Fixed - JBIDE-12806 - Annotations location in the JAX-RS Metamodel are not updated after code changes
https://issues.jboss.org/browse/JBIDE-12806
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationLocator.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationLocator.java 2012-10-12 10:03:46 UTC (rev 44471)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JavaAnnotationLocator.java 2012-10-12 11:46:13 UTC (rev 44472)
@@ -12,13 +12,20 @@
import java.util.List;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
+import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.jboss.tools.ws.jaxrs.core.internal.utils.Logger;
/**
* @author Xavier Coulon
@@ -27,9 +34,12 @@
public class JavaAnnotationLocator extends ASTVisitor {
private final int location;
+ private final IMethod parentMethod;
+
private Annotation locatedAnnotation;
- public JavaAnnotationLocator(final int location) {
+ public JavaAnnotationLocator(final IJavaElement parentElement, final int location) {
+ this.parentMethod = (parentElement.getElementType() == IJavaElement.METHOD) ? (IMethod) parentElement : null;
this.location = location;
}
@@ -61,16 +71,6 @@
}
/**
- * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodDeclaration)
- */
- @Override
- public boolean visit(MethodDeclaration node) {
- visitExtendedModifiers((List<?>) node.getStructuralProperty(MethodDeclaration.MODIFIERS2_PROPERTY));
- // visit children to look for SingleVariableDeclaration
- return true;
- }
-
- /**
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeDeclaration)
*/
@Override
@@ -81,16 +81,74 @@
}
/**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodDeclaration)
+ */
+ @Override
+ public boolean visit(MethodDeclaration declaration) {
+ visitExtendedModifiers((List<?>) declaration.getStructuralProperty(MethodDeclaration.MODIFIERS2_PROPERTY));
+ return this.locatedAnnotation == null;
+ }
+
+ /*
+ * (non-Javadoc)
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleVariableDeclaration)
*/
@Override
- public boolean visit(SingleVariableDeclaration node) {
- visitExtendedModifiers((List<?>) node.getStructuralProperty(SingleVariableDeclaration.MODIFIERS2_PROPERTY));
- // no need to visit furthermore
+ public boolean visit(SingleVariableDeclaration variableDeclaration) {
+ // skip if parentMethod is undefined or if annotation is already located
+ if (this.parentMethod == null || this.locatedAnnotation != null) {
+ return false;
+ }
+ try {
+ if (DOMUtils.nodeMatches(variableDeclaration, location)) {
+ final IVariableBinding variableDeclarationBinding = variableDeclaration.resolveBinding();
+ final IAnnotationBinding[] annotationBindings = variableDeclarationBinding.getAnnotations();
+ // retrieve the parameter index in the parent method
+ final ILocalVariable localVariable = getLocalVariable(variableDeclarationBinding);
+ if (localVariable != null) {
+ final IAnnotation[] variableAnnotations = localVariable.getAnnotations();
+ for (int j = 0; j < annotationBindings.length; j++) {
+ final IAnnotation javaAnnotation = variableAnnotations[j];
+ if (RangeUtils.matches(javaAnnotation.getSourceRange(), location)) {
+ final IAnnotationBinding javaAnnotationBinding = annotationBindings[j];
+ this.locatedAnnotation = BindingUtils.toAnnotation(javaAnnotationBinding, javaAnnotation);
+ break;
+ }
+ }
+ }
+ // TODO : add support for thrown exceptions
+ }
+ } catch (JavaModelException e) {
+ Logger.error("Failed to analyse compilation unit method '" + this.parentMethod.getElementName() + "'", e);
+ }
+
+ // no need to carry on from here
return false;
+
}
-
+
/**
+ * Returns the localVariable associated with the given variable declaration binding, or null if it could not be found
+ * @param variableDeclarationBinding
+ * @return
+ * @throws JavaModelException
+ */
+ private ILocalVariable getLocalVariable(final IVariableBinding variableDeclarationBinding)
+ throws JavaModelException {
+ int i = -1;
+ for (String paramName : parentMethod.getParameterNames()) {
+ i++;
+ if (paramName.equals(variableDeclarationBinding.getName())) {
+ break;
+ }
+ }
+ if(i>=0) {
+ return this.parentMethod.getParameters()[i];
+ }
+ return null;
+ }
+
+ /**
* Visits the modifiers.
*
* @param modifiers
@@ -103,7 +161,8 @@
if (DOMUtils.nodeMatches(annotation, location)) {
final IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
if (annotationBinding != null) {
- this.locatedAnnotation = BindingUtils.toAnnotation(annotationBinding);
+ final IAnnotation javaAnnotation = (IAnnotation) annotationBinding.getJavaElement();
+ this.locatedAnnotation = BindingUtils.toAnnotation(annotationBinding, javaAnnotation);
}
}
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java 2012-10-12 10:03:46 UTC (rev 44471)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtils.java 2012-10-12 11:46:13 UTC (rev 44472)
@@ -376,7 +376,7 @@
final IJavaElement element = compilationUnit.getElementAt(location);
final ASTNode astChildNode = DOMUtils.getASTNodeByTypeAndLocation(ast, element.getElementType(), location);
if (astChildNode != null) {
- final JavaAnnotationLocator annotationLocator = new JavaAnnotationLocator(location);
+ final JavaAnnotationLocator annotationLocator = new JavaAnnotationLocator(element, location);
astChildNode.accept(annotationLocator);
return annotationLocator.getLocatedAnnotation();
}
Added: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/RangeUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/RangeUtils.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/RangeUtils.java 2012-10-12 11:46:13 UTC (rev 44472)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.core.jdt;
+
+import org.eclipse.jdt.core.ISourceRange;
+
+/**
+ * @author Xavier Coulon
+ *
+ */
+public class RangeUtils {
+
+ /**
+ * Private constructor for this utility class
+ */
+ public RangeUtils() {
+ }
+
+ /**
+ * Returns true if the source range matches the given position, false otherwise
+ * @param sourceRange
+ * @param position
+ * @return
+ */
+ public static boolean matches(final ISourceRange range, final int position) {
+ return range.getOffset() <= position && position <= (range.getOffset() + range.getLength());
+ }
+
+}
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.core/src/org/jboss/tools/ws/jaxrs/core/jdt/RangeUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java 2012-10-12 10:03:46 UTC (rev 44471)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/contentassist/PathParamAnnotationValueCompletionProposalComputer.java 2012-10-12 11:46:13 UTC (rev 44472)
@@ -20,6 +20,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.ui.text.IJavaPartitions;
@@ -75,40 +76,43 @@
if (metamodel == null) {
return Collections.emptyList();
}
-// final IJavaElement invocationElement = javaContext.getCompilationUnit().getElementAt(
-// context.getInvocationOffset());
-//
-// // ICompilationUnit.getElementAt(int) method may return null
-// if (invocationElement != null && invocationElement.getElementType() == IJavaElement.METHOD) {
-// IJaxrsResourceMethod resourceMethod = metamodel.getElement(invocationElement,
-// IJaxrsResourceMethod.class);
-// // the java method must be associated with a JAX-RS Resource Method.
-// if (resourceMethod != null) {
-// for (JavaMethodParameter methodParameter : resourceMethod.getJavaMethodParameters()) {
-// for (Annotation annotation : methodParameter.getAnnotations().values()) {
-// final ISourceRange range = annotation.getSourceRange();
-// if (annotation.getFullyQualifiedName().equals(PATH_PARAM.qualifiedName) && range != null
-// && context.getInvocationOffset() >= range.getOffset()
-// && context.getInvocationOffset() < (range.getOffset() + range.getLength())) {
-// // completion proposal on @PathParam method
-// // annotation
-// return internalComputePathParamProposals(javaContext, resourceMethod);
-// }
-//
-// }
-// }
-// }
-// }
-
+ // final IJavaElement invocationElement = javaContext.getCompilationUnit().getElementAt(
+ // context.getInvocationOffset());
+ //
+ // // ICompilationUnit.getElementAt(int) method may return null
+ // if (invocationElement != null && invocationElement.getElementType() == IJavaElement.METHOD) {
+ // IJaxrsResourceMethod resourceMethod = metamodel.getElement(invocationElement,
+ // IJaxrsResourceMethod.class);
+ // // the java method must be associated with a JAX-RS Resource Method.
+ // if (resourceMethod != null) {
+ // for (JavaMethodParameter methodParameter : resourceMethod.getJavaMethodParameters()) {
+ // for (Annotation annotation : methodParameter.getAnnotations().values()) {
+ // final ISourceRange range = annotation.getSourceRange();
+ // if (annotation.getFullyQualifiedName().equals(PATH_PARAM.qualifiedName) && range != null
+ // && context.getInvocationOffset() >= range.getOffset()
+ // && context.getInvocationOffset() < (range.getOffset() + range.getLength())) {
+ // // completion proposal on @PathParam method
+ // // annotation
+ // return internalComputePathParamProposals(javaContext, resourceMethod);
+ // }
+ //
+ // }
+ // }
+ // }
+ // }
+
final int invocationOffset = context.getInvocationOffset();
final ICompilationUnit compilationUnit = javaContext.getCompilationUnit();
final Annotation annotation = JdtUtils.resolveAnnotationAt(invocationOffset, compilationUnit);
- if(annotation != null && annotation.getFullyQualifiedName().equals(PATH_PARAM.qualifiedName)) {
- final IJaxrsResourceMethod resourceMethod = metamodel.getElement(annotation.getJavaParent(),
- IJaxrsResourceMethod.class);
- return internalComputePathParamProposals(javaContext, resourceMethod);
+ if (annotation != null && annotation.getFullyQualifiedName().equals(PATH_PARAM.qualifiedName)) {
+ final IJavaElement javaMethod = annotation.getJavaAnnotation().getAncestor(IJavaElement.METHOD);
+ if (javaMethod != null) {
+ final IJaxrsResourceMethod resourceMethod = metamodel.getElement(javaMethod,
+ IJaxrsResourceMethod.class);
+ return internalComputePathParamProposals(javaContext, resourceMethod);
+ }
}
-
+
} catch (Exception e) {
Logger.error("Failed to compute completion proposal", e);
}
Modified: trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java 2012-10-12 10:03:46 UTC (rev 44471)
+++ trunk/ws/tests/org.jboss.tools.ws.jaxrs.core.test/src/org/jboss/tools/ws/jaxrs/core/jdt/JdtUtilsTestCase.java 2012-10-12 11:46:13 UTC (rev 44472)
@@ -757,7 +757,7 @@
final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset, method.getCompilationUnit());
// verification
assertThat(foundAnnotation, notNullValue());
- assertThat(foundAnnotation.getJavaAnnotation(), nullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
}
@Test
@@ -772,8 +772,7 @@
final Annotation foundAnnotation = JdtUtils.resolveAnnotationAt(offset, customerType.getCompilationUnit());
// verification
assertThat(foundAnnotation, notNullValue());
- // iannotation retrieved from this method is null and does not need to be evaluated anyway.
- assertThat(foundAnnotation.getJavaAnnotation(), nullValue());
+ assertThat(foundAnnotation.getJavaAnnotation(), notNullValue());
}
@Test
12 years, 3 months