-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FORGE-1076 Added support to detect conflicting top-level @paths.
This is done through a JavaResourceVisitor that verifies whether existing JAX-RS resource classes contain @path annotation values that match the one for the Resource being created. The visitor also verifies whether the matching @path is for an existing JAX-RS resource that will eventually be overwritten.
- Loading branch information
1 parent
2a8c58c
commit ced1c2c
Showing
3 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
javaee-impl/src/main/java/org/jboss/forge/spec/javaee/rest/RestResourceTypeVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.spec.javaee.rest; | ||
|
||
import java.io.FileNotFoundException; | ||
|
||
import org.jboss.forge.parser.java.JavaSource; | ||
import org.jboss.forge.resources.java.JavaResource; | ||
import org.jboss.forge.resources.java.JavaResourceVisitor; | ||
|
||
class RestResourceTypeVisitor implements JavaResourceVisitor | ||
{ | ||
private String proposedPath; | ||
private boolean found; | ||
private JavaSource<?> javaSource; | ||
|
||
public void setProposedPath(String proposedPath) | ||
{ | ||
this.proposedPath = proposedPath; | ||
} | ||
|
||
public String getQualifiedClassNameForMatch() | ||
{ | ||
if(javaSource != null) | ||
{ | ||
return javaSource.getQualifiedName(); | ||
} | ||
return null; | ||
} | ||
|
||
public boolean isFound() | ||
{ | ||
return found; | ||
} | ||
|
||
public void setFound(boolean found) | ||
{ | ||
this.found = found; | ||
} | ||
|
||
@Override | ||
public void visit(JavaResource javaResource) | ||
{ | ||
if (!found) | ||
{ | ||
try | ||
{ | ||
if (javaResource.getJavaSource().getAnnotation("javax.ws.rs.Path") != null) | ||
{ | ||
String path = javaResource.getJavaSource().getAnnotation("javax.ws.rs.Path") | ||
.getStringValue(); | ||
String absolutePath = path.endsWith("/") ? path.substring(0,path.lastIndexOf('/')) : path; | ||
if (absolutePath.equals(proposedPath)) | ||
{ | ||
javaSource = javaResource.getJavaSource(); | ||
found = true; | ||
} | ||
} | ||
} | ||
catch (FileNotFoundException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters