List of usage examples for org.eclipse.jdt.core IMemberValuePair getValue
Object getValue();
From source file:at.bestsolution.efxclipse.tooling.model.internal.utils.Util.java
License:Open Source License
@SuppressWarnings("unchecked") public static <R> R getAnnotationMemberValue(IAnnotation annotation, String name) throws JavaModelException { for (IMemberValuePair pair : annotation.getMemberValuePairs()) { if (name.equals(pair.getMemberName())) { return (R) pair.getValue(); }//from w w w .ja v a 2 s . c o m } return null; }
From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java
License:Open Source License
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException { fBuffer.append('@'); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);//from www .jav a2s. c o m IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); if (memberValuePairs.length == 0) return; fBuffer.append('('); for (int i = 0; i < memberValuePairs.length; i++) { if (i > 0) fBuffer.append(JavaElementLabels.COMMA_STRING); IMemberValuePair memberValuePair = memberValuePairs[i]; fBuffer.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName())); fBuffer.append('='); appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags); } fBuffer.append(')'); }
From source file:cn.ieclipse.adt.ext.jdt.JavaSelection.java
License:Apache License
public List<TypeMapping> getTypeMappings() { ArrayList<TypeMapping> list = new ArrayList<TypeMapping>(); ICompilationUnit[] arrays = units.toArray(new ICompilationUnit[] {}); for (ICompilationUnit unit : arrays) { IType[] types;//from w w w . j av a 2s .c o m try { types = unit.getAllTypes(); } catch (JavaModelException e) { // TODO e.printStackTrace(); continue; } for (IType type : types) { IAnnotation nt = type.getAnnotation("Table"); if (nt != null && nt.exists()) { IMemberValuePair[] tVars; String table = ""; try { tVars = nt.getMemberValuePairs(); for (IMemberValuePair tVar : tVars) { if ("name".equals(tVar.getMemberName())) { table = (String) tVar.getValue(); } } list.add(new TypeMapping(table, type)); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } return list; }
From source file:cn.ieclipse.adt.ext.jdt.SourceAnalysis.java
License:Apache License
public static String getSQL(TypeMapping typeMapping, boolean format) { StringBuilder sb = new StringBuilder(); sb.append("create TABLE "); sb.append(typeMapping.getTable());//from w ww . j ava 2 s . com sb.append(" ( "); if (format) { sb.append(LF); } try { IField[] fds = typeMapping.getType().getFields(); for (IField iField : fds) { String fieldType = iField.getTypeSignature(); IAnnotation nc = iField.getAnnotation("Column"); if (nc != null && nc.exists()) { ColumnMeta meta = new ColumnMeta(); meta.type = getColumnBySig(fieldType); IMemberValuePair[] mvps = nc.getMemberValuePairs(); for (IMemberValuePair imvp : mvps) { String mn = imvp.getMemberName(); Object mv = imvp.getValue(); if ("name".equals(mn)) { meta.name = (String) mv; } else if ("id".equals(mn)) { meta.id = (Boolean) mv; meta.haveId = true; } else if ("notNull".equals(mn)) { meta.notNull = (Boolean) mv; meta.haveNotNull = true; } else if ("defaultValue".equals(mn)) { meta.defaultValue = (String) mv; meta.haveDefaultValue = true; } } sb.append(meta.toSQL()); sb.append(", "); if (format) { sb.append(LF); } } // end if } // end for int len = sb.length() - 2; if (format) { len = len - LF.length(); } sb.delete(len, sb.length()); sb.append(")"); sb.append(LF); } catch (Exception e) { e.printStackTrace(); return ""; } return sb.toString(); }
From source file:com.codenvy.ide.ext.java.server.SourcesFromBytecodeGenerator.java
License:Open Source License
public void appendAnnotationLabel(IAnnotation annotation, long flags, StringBuilder builder) throws JavaModelException { builder.append('@'); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags, builder);//from w ww. j ava 2s . co m IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); if (memberValuePairs.length == 0) return; builder.append('('); for (int i = 0; i < memberValuePairs.length; i++) { if (i > 0) builder.append(JavaElementLabels.COMMA_STRING); IMemberValuePair memberValuePair = memberValuePairs[i]; builder.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName())); builder.append('='); appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags, builder); } builder.append(')'); }
From source file:com.curlap.orb.plugin.generator.CurlClassGeneratorFactory.java
License:Open Source License
private String getSavePath(IAnnotation annotation) throws CurlGenerateException { try {//from w w w.j a va2s. c o m for (IMemberValuePair pair : annotation.getMemberValuePairs()) { String memberName = pair.getMemberName(); if (memberName.equals("savePath")) return (String) pair.getValue(); } } catch (JavaModelException e) { throw new CurlGenerateException(e); } // TODO: package name (e.g. COM.TEST.ABC.Foo --> COM/TEST/ABC/) return ""; }
From source file:com.curlap.orb.plugin.generator.CurlClassGeneratorFactory.java
License:Open Source License
public CurlClassGenerator createGenerator(ICompilationUnit iCompilationUnit) throws CurlGenerateException { ICompilationUnit source = iCompilationUnit; try {/*w w w. j av a 2 s . co m*/ for (IType iType : source.getAllTypes()) { for (IAnnotation annotation : iType.getAnnotations()) { String name = annotation.getElementName(); if (name.equals("AutoGenerateCurlServiceClient")) { String savePath = getSavePath(annotation); for (IMemberValuePair pair : annotation.getMemberValuePairs()) { if (pair.getMemberName().equals("serviceType")) if (((String) pair.getValue()).equals("HttpSession")) return new CurlHttpSessionServiceClassGeneratorImpl(source, savePath); } return new CurlDIServiceClassGeneratorImpl(source, savePath); } else if (name.equals("AutoGenerateCurlDto")) { String savePath = getSavePath(annotation); return new CurlDataClassGeneratorImpl(source, savePath); } else if (name.equals("AutoGenerateCurlException")) { String savePath = getSavePath(annotation); return new CurlExceptionGeneratorImpl(source, savePath); } } } } catch (JavaModelException e) { throw new CurlGenerateException(e); } //throw new CurlGenerateException("Cannot create generator."); return null; }
From source file:com.curlap.orb.plugin.generator.impl.CurlDIServiceClassGeneratorImpl.java
License:Open Source License
@Override public VelocityContext generateClass() throws CurlGenerateException { ICompilationUnit source = iCompilationUnit; VelocityContext context = super.generateClass(); String beanId = null;/*from ww w. j av a2 s . co m*/ try { for (IType iType : source.getAllTypes()) { // annotation for (IAnnotation iAnnotation : iType.getAnnotations()) { if (iAnnotation.getElementName().equals("AutoGenerateCurlServiceClient")) { for (IMemberValuePair pair : iAnnotation.getMemberValuePairs()) { String memberName = pair.getMemberName(); if (memberName.equals("serviceBeanId")) beanId = (String) pair.getValue(); } } // "@Service" is a Spring framework annotation. // See org.springframework.stereotype.Service if (iAnnotation.getElementName().equals("Service")) { for (IMemberValuePair pair : iAnnotation.getMemberValuePairs()) { String memberName = pair.getMemberName(); if (memberName.equals("value")) beanId = (String) pair.getValue(); } } } if (beanId == null || beanId.length() == 0) throw new CurlGenerateException( "DI serivce needs 'bean id'. See 'serviceBeanId' of @AutoGenerateCurlServiceClient annotation."); } context.put("server_component", beanId); context.put("superclass", "ApplicationContextClient"); return context; } catch (JavaModelException e) { throw new CurlGenerateException(e); } }
From source file:com.curlap.orb.plugin.generator.impl.CurlServiceClassGenerator.java
License:Open Source License
@Override public VelocityContext generateClass() throws CurlGenerateException { ICompilationUnit source = iCompilationUnit; Set<String> importPackages = new HashSet<String>(); List<Method> methods = new ArrayList<Method>(); String packageName = null;/*from w ww . j a va 2 s . c om*/ String targetInterface = null; JavadocContent classJavadoc = null; String className = null; boolean returnTypeIsNullable = true; boolean generateTestTemplate = false; boolean generateAsyncMethod = true; importPackages.add("COM.CURLAP.ORB"); try { for (IType iType : source.getAllTypes()) { // package IPackageFragment iPackageFragment = iType.getPackageFragment(); packageName = (iPackageFragment != null ? iPackageFragment.getElementName().toUpperCase() : ""); // javadoc classJavadoc = JavaElementAnalyzer.getJavaDoc(iType); // class name className = iType.getElementName(); if (className == null) throw new CurlGenerateException("There is no class name."); // superclass String superclass = iType.getSuperclassName(); if (superclass != null) { methods.addAll( addMethodsOfSuperclass(source, superclass, importPackages, returnTypeIsNullable)); // NOTE: the following code would be not necessary // superclassBuf.append(", "); // superclassBuf.append(superclass); // addImportedPackageIfNecessary(importPackages, superclass); } // annotation for (IAnnotation iAnnotation : iType.getAnnotations()) { if (iAnnotation.getElementName().equals("AutoGenerateCurlServiceClient")) { for (IMemberValuePair pair : iAnnotation.getMemberValuePairs()) { String memberName = pair.getMemberName(); if (memberName.equals("generateTestTemplate")) generateTestTemplate = ((Boolean) pair.getValue()).booleanValue(); if (memberName.equals("generateAsyncMethod")) generateAsyncMethod = ((Boolean) pair.getValue()).booleanValue(); if (memberName.equals("targetInterface")) targetInterface = (String) pair.getValue(); } } if (iAnnotation.getElementName().equals("DefaultNotNull")) returnTypeIsNullable = false; } // interface String[] interfaceNames = iType.getSuperInterfaceNames(); if (interfaceNames.length > 0) { if (interfaceNames.length == 1) targetInterface = interfaceNames[0]; // In the case of only one interface else { boolean hasSuchInterface = false; for (String interfaceName : interfaceNames) if (interfaceName.equals(targetInterface)) hasSuchInterface = true; if (!hasSuchInterface) throw new CurlGenerateException("'targetInterface' is wrong interface."); } } if (targetInterface != null) { // Add interfaces' methods TypeNameMatch typeNameMatch = new JavaElementSearcher(source).searchClassInfo(targetInterface); IType interfaceIType = typeNameMatch.getType(); className = targetInterface; fileName = className + ".scurl"; methods.addAll(getMethodsFromIType(interfaceIType, importPackages, returnTypeIsNullable)); addImportedPackageIfNecessary(importPackages, targetInterface); // Add interfaces' methods of interface. for (String interfaceNamesOfInterface : interfaceIType.getSuperInterfaceNames()) { TypeNameMatch typeNameMatchOfInterface = new JavaElementSearcher( interfaceIType.getCompilationUnit()).searchClassInfo(interfaceNamesOfInterface); methods.addAll(getMethodsFromIType(typeNameMatchOfInterface.getType(), importPackages, returnTypeIsNullable)); } } else { // methods methods.addAll(getMethodsFromIType(iType, importPackages, returnTypeIsNullable)); } } } catch (JavaModelException e) { throw new CurlGenerateException(e); } // merge to velocity. VelocityContext context = new VelocityContext(); context.put("is_template", generateTestTemplate); context.put("has_async_method", generateAsyncMethod); context.put("package_name", packageName); context.put("import_packages", importPackages); context.put("javadocContent", classJavadoc); context.put("class_name", className); context.put("methods", methods); return context; }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JaxWsUtils.java
License:Open Source License
/** * Searches all the Java types from a Java project that are annotated with @WebService. * * @param jp the containing Java project * @param monitor the progress monitor//from w w w . j a v a 2 s . co m * @param includeClasses true to include classes in the search results * @param includeInterfaces true to include the interfaces in the search results * @return a Map * <p> * Key = the qualified name of the annotated type<br /> * Value = the associated service name (in the target WSDL) * </p> * * @throws CoreException if the search could not be launched */ public static Map<String, String> getJaxAnnotatedJavaTypes(IJavaProject jp, IProgressMonitor monitor, final boolean includeClasses, final boolean includeInterfaces) throws CoreException { jp.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor); jp.getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor); final Map<String, String> classNameToServiceName = new HashMap<String, String>(); SearchPattern pattern = SearchPattern.createPattern(WEB_WS_ANNOTATION, IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); // This is what we do when we find a match SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { // We get the Java type that is annotated with @WebService if (match.getElement() instanceof IType) { // Find the annotation IType type = (IType) match.getElement(); if (type.isInterface() && includeInterfaces || type.isClass() && includeClasses) { IAnnotation ann = type.getAnnotation(WEB_WS_ANNOTATION); if (!ann.exists()) ann = type.getAnnotation(SHORT_WEB_WS_ANNOTATION); // Get the service name and store it if (ann.exists()) { String serviceName = null; for (IMemberValuePair pair : ann.getMemberValuePairs()) { if ("serviceName".equalsIgnoreCase(pair.getMemberName())) { serviceName = (String) pair.getValue(); break; } } if (serviceName == null) serviceName = type.getElementName() + "Service"; classNameToServiceName.put(type.getFullyQualifiedName(), serviceName); } } } } }; new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { jp }, false), requestor, monitor); return classNameToServiceName; }