Skip to content

Commit

Permalink
ResourceVisitor extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinSviridov committed Aug 7, 2015
1 parent 460dbc2 commit 20ccf2c
Show file tree
Hide file tree
Showing 26 changed files with 533 additions and 263 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.mulesoft.jaxrs.raml.annotation.model.apt;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.DeclaredType;

Expand Down Expand Up @@ -76,4 +79,22 @@ public IAnnotationModel[] getSubAnnotations(String pairName) {
return new IAnnotationModel[0];
}


@Override
public String getCanonicalName() {
DeclaredType annotationType = mirror.getAnnotationType();
Element element = annotationType.asElement();
ArrayList<String> list = new ArrayList<String>();
while(element!=null){
list.add(element.getSimpleName().toString());
}
Collections.reverse(list);
StringBuilder bld = new StringBuilder();
for(String s : list){
bld.append(s).append(".");
}
String result = bld.substring(0, bld.length()-1);
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,10 @@ public IAnnotationModel[] getSubAnnotations(String pairName) {

}


@Override
public String getCanonicalName() {
return annotation.getElementName();
}

}
Original file line number Diff line number Diff line change
@@ -1,146 +1,155 @@
package com.mulesoft.jaxrs.raml.generator.popup.actions;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.jface.preference.IPreferenceStore;
import org.raml.model.ActionType;
import org.raml.model.Protocol;

import com.mulesoft.jaxrs.raml.generator.eclipse.JAXRSTORamlPlagin;

final class PreferencesConfig implements IEditableRamlConfig {

public static final String TITLE="title";
public static final String VERSION="version";
public static final String BASEURL="baseurl";
public static final String PROTOCOLS="protocols";
private static final String SINGLE = "single";
private static final String SORTED = "sorted";
private static final String FULL_TREE = "fullTree";

protected IPreferenceStore preferences=JAXRSTORamlPlagin.getInstance().getPreferenceStore();


public String getTitle() {
String string = preferences.getString(TITLE);
if (string==null||string.length()==0){
return "Please type API title here";
}
return string;
}


public String getResponseCode(ActionType type) {
String string = preferences.getString(getResponseCodeKey(type));
if (string!=null&&string.trim().length()>0){
return string;
}
return "200";
}


public Set<Protocol> getProtocols() {
String string = preferences.getString(PROTOCOLS);
if (string!=null&&string.length()>0){
String[] split = string.split(",");
HashSet<Protocol>s=new HashSet<Protocol>();
for (String str:split){
s.add(Protocol.valueOf(str));
}
return s;
}
return Collections.singleton(Protocol.HTTP);
}

public void setProtocols(Set<Protocol> ps) {
StringBuilder bld=new StringBuilder();
int a=0;
for (Protocol p:ps){
bld.append(p.name());
a++;
if (a!=ps.size()){
bld.append(",");
}
}
preferences.setValue(PROTOCOLS, bld.toString());
}



public String getBaseUrl() {
String string = preferences.getString(BASEURL);
if (string==null||string.length()==0){
return "http://example.com";
}
return string;
}


public void setTitle(String title) {
preferences.putValue(TITLE,title);
}



public void setBaseUrl(String baseUrl) {
preferences.setValue(BASEURL, baseUrl);
}


public void setVersion(String value) {
preferences.setValue(VERSION, value);
}


public String getVersion() {
String string = preferences.getString(VERSION);
if (string==null||string.length()==0){
return "v1";
}
return string;
}


public boolean isSingle() {
return preferences.getBoolean(SINGLE);
}




public void setSingle(boolean selection) {
preferences.setValue(SINGLE, selection);
}



public boolean isSorted() {
return !preferences.getBoolean(SORTED);
}


public void setSorted(boolean selection) {
preferences.setValue(SORTED, !selection);
}


public void setDefaultResponseCode(ActionType a, String text) {
preferences.putValue(getResponseCodeKey(a), text);
}

private String getResponseCodeKey(ActionType a) {
return a.name()+".responseCode";
}


public boolean doFullTree() {
return !preferences.getBoolean(FULL_TREE);
}


public void setDoFullTree(boolean selection) {
preferences.setValue(FULL_TREE, !selection);
}
package com.mulesoft.jaxrs.raml.generator.popup.actions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.jface.preference.IPreferenceStore;
import org.raml.model.ActionType;
import org.raml.model.Protocol;

import com.mulesoft.jaxrs.raml.annotation.model.IResourceVisitorExtension;
import com.mulesoft.jaxrs.raml.generator.eclipse.JAXRSTORamlPlagin;

final class PreferencesConfig implements IEditableRamlConfig {

public static final String TITLE="title";
public static final String VERSION="version";
public static final String BASEURL="baseurl";
public static final String PROTOCOLS="protocols";
private static final String SINGLE = "single";
private static final String SORTED = "sorted";
private static final String FULL_TREE = "fullTree";

protected IPreferenceStore preferences=JAXRSTORamlPlagin.getInstance().getPreferenceStore();


public String getTitle() {
String string = preferences.getString(TITLE);
if (string==null||string.length()==0){
return "Please type API title here";
}
return string;
}


public String getResponseCode(ActionType type) {
String string = preferences.getString(getResponseCodeKey(type));
if (string!=null&&string.trim().length()>0){
return string;
}
return "200";
}


public Set<Protocol> getProtocols() {
String string = preferences.getString(PROTOCOLS);
if (string!=null&&string.length()>0){
String[] split = string.split(",");
HashSet<Protocol>s=new HashSet<Protocol>();
for (String str:split){
s.add(Protocol.valueOf(str));
}
return s;
}
return Collections.singleton(Protocol.HTTP);
}

public void setProtocols(Set<Protocol> ps) {
StringBuilder bld=new StringBuilder();
int a=0;
for (Protocol p:ps){
bld.append(p.name());
a++;
if (a!=ps.size()){
bld.append(",");
}
}
preferences.setValue(PROTOCOLS, bld.toString());
}



public String getBaseUrl() {
String string = preferences.getString(BASEURL);
if (string==null||string.length()==0){
return "http://example.com";
}
return string;
}


public void setTitle(String title) {
preferences.putValue(TITLE,title);
}



public void setBaseUrl(String baseUrl) {
preferences.setValue(BASEURL, baseUrl);
}


public void setVersion(String value) {
preferences.setValue(VERSION, value);
}


public String getVersion() {
String string = preferences.getString(VERSION);
if (string==null||string.length()==0){
return "v1";
}
return string;
}


public boolean isSingle() {
return preferences.getBoolean(SINGLE);
}




public void setSingle(boolean selection) {
preferences.setValue(SINGLE, selection);
}



public boolean isSorted() {
return !preferences.getBoolean(SORTED);
}


public void setSorted(boolean selection) {
preferences.setValue(SORTED, !selection);
}


public void setDefaultResponseCode(ActionType a, String text) {
preferences.putValue(getResponseCodeKey(a), text);
}

private String getResponseCodeKey(ActionType a) {
return a.name()+".responseCode";
}


public boolean doFullTree() {
return !preferences.getBoolean(FULL_TREE);
}


public void setDoFullTree(boolean selection) {
preferences.setValue(FULL_TREE, !selection);
}


@Override
public List<IResourceVisitorExtension> getExtensions() {
return new ArrayList<IResourceVisitorExtension>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public interface IAnnotationModel {
*/
public String getName();

/**
* <p>getFullyQualifiedName.</p>
*
* @return a {@link java.lang.String} object.
*/
String getCanonicalName();

/**
* <p>getValue.</p>
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mulesoft.jaxrs.raml.annotation.model;

import java.util.List;
import java.util.Set;

import org.raml.model.ActionType;
Expand Down Expand Up @@ -77,6 +78,11 @@ public interface IRamlConfig {
*/
boolean doFullTree();


/**
* <p>getExtensions.</p>
*
* @return list of resource visitor extensions
*/
List<IResourceVisitorExtension> getExtensions();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mulesoft.jaxrs.raml.annotation.model;

public interface IResourceVisitorExtension {

boolean generateSchema(ITypeModel type);

}
Loading

0 comments on commit 20ccf2c

Please sign in to comment.