List of usage examples for javax.lang.model.element ExecutableElement getSimpleName
@Override Name getSimpleName();
From source file:Main.java
public static String nameWithoutJavaBeansPrefix(ExecutableElement element) { final String rawName = element.getSimpleName().toString(); return nameWithoutJavaBeansPrefix(rawName); }
From source file:org.leandreck.endpoints.processor.model.MethodNodeFactory.java
private static String defineName(final ExecutableElement methodElement) { return methodElement.getSimpleName().toString(); }
From source file:org.inferred.freebuilder.processor.util.AnnotationSource.java
/** * Returns true if {@code annotation} has a single element named "value", letting us drop the * 'value=' prefix in the source code./*ww w .j av a 2s . c o m*/ */ private static boolean hasSingleValueWithDefaultKey(AnnotationMirror annotation) { if (annotation.getElementValues().size() != 1) { return false; } ExecutableElement key = getOnlyElement(annotation.getElementValues().keySet()); return key.getSimpleName().contentEquals("value"); }
From source file:de.hasait.genesis.base.util.GenesisUtils.java
public static boolean isGetter(final Element pElement, final String pPrefix) { GenesisUtils.assertNotNull(pPrefix); if (isPublicMemberMethod(pElement)) { final ExecutableElement element = (ExecutableElement) pElement; final String simpleName = element.getSimpleName().toString(); return simpleName.startsWith(pPrefix) && simpleName.length() > pPrefix.length() // && element.getReturnType() != null && element.getParameters().isEmpty() // ;//from w ww . jav a2 s . c o m } return false; }
From source file:de.hasait.genesis.base.util.GenesisUtils.java
public static boolean isSetter(final Element pElement, final String pPrefix) { GenesisUtils.assertNotNull(pPrefix); if (isPublicMemberMethod(pElement)) { final ExecutableElement element = (ExecutableElement) pElement; final String simpleName = element.getSimpleName().toString(); return simpleName.startsWith(pPrefix) && simpleName.length() > pPrefix.length() // && element.getParameters().size() == 1 // no return type check to support fluent setters ;/*from w w w . j ava 2s.c o m*/ } return false; }
From source file:com.github.jdot.type.Property.java
/** * Returns new BeanProperty instance if the specified element is a JavaBean accessor method, otherwise null. * /* w ww .j a va 2 s . co m*/ * @param element * @return */ public static Property build(Type owner, ExecutableElement element) { Property beanProperty = null; String name = null; boolean propertyFound = true; boolean writeable = false; String type = null; // Check modifiers boolean publicFound = false; boolean staticFound = false; for (Modifier modifier : element.getModifiers()) { if (Modifier.PUBLIC.equals(modifier)) { publicFound = true; } if (Modifier.STATIC.equals(modifier)) { staticFound = true; } } if (!publicFound || staticFound) { propertyFound = false; } // Check method name if (propertyFound) { String methodName = element.getSimpleName().toString(); if (methodName.startsWith("set") && Character.isUpperCase(methodName.charAt(3))) { name = StringUtils.uncapitalize(methodName.substring(3)); writeable = true; } else if (methodName.startsWith("get") && Character.isUpperCase(methodName.charAt(3))) { name = StringUtils.uncapitalize(methodName.substring(3)); } else if (methodName.startsWith("is") && Character.isUpperCase(methodName.charAt(2))) { name = StringUtils.uncapitalize(methodName.substring(2)); } else { propertyFound = false; } } // Check arguments / return type if (propertyFound) { if (writeable) { if (element.getParameters().size() == 1 && TypeKind.VOID.equals(element.getReturnType().getKind())) { type = element.getParameters().get(0).asType().toString(); } else { propertyFound = false; } } else { if (TypeKind.VOID.equals(element.getReturnType().getKind())) { propertyFound = false; } else { type = element.getReturnType().toString(); } } } if (propertyFound) { beanProperty = new Property(owner, element, name, type, writeable); } return beanProperty; }
From source file:auto.parse.processor.AutoParseProcessor.java
private static boolean isToStringOrEqualsOrHashCode(ExecutableElement method) { String name = method.getSimpleName().toString(); return ((name.equals("toString") || name.equals("hashCode")) && method.getParameters().isEmpty()) || (name.equals("equals") && method.getParameters().size() == 1 && method.getParameters().get(0).asType().toString().equals("java.lang.Object")); }
From source file:org.mule.devkit.validation.InjectValidator.java
@Override public void validate(DevKitTypeElement typeElement, GeneratorContext context) throws ValidationException { for (VariableElement variable : typeElement.getFieldsAnnotatedWith(Inject.class)) { if (!variable.asType().toString().equals(MuleContext.class.getName()) && !variable.asType().toString().equals(ObjectStoreManager.class.getName()) && !variable.asType().toString().equals(TransactionManager.class.getName()) && !variable.asType().toString().equals(QueueManager.class.getName()) && !variable.asType().toString().equals(MuleConfiguration.class.getName()) && !variable.asType().toString().equals(LifecycleManager.class.getName()) && !variable.asType().toString().equals(ClassLoader.class.getName()) && !variable.asType().toString().equals(ExpressionManager.class.getName()) && !variable.asType().toString().equals(EndpointFactory.class.getName()) && !variable.asType().toString().equals(MuleClient.class.getName()) && !variable.asType().toString().equals(SystemExceptionHandler.class.getName()) && !variable.asType().toString().equals(SecurityManager.class.getName()) && !variable.asType().toString().equals(WorkManager.class.getName()) && !variable.asType().toString().equals(ObjectStore.class.getName()) && !variable.asType().toString().equals(Registry.class.getName())) { throw new ValidationException(variable, "I don't know how to inject the type " + variable.asType().toString() + " in field " + variable.getSimpleName().toString() + ". " + "The only types I know how to inject are: MuleContext, ObjectStoreManager, ObjectStore, TransactionManager, QueueManager, MuleConfiguration, LifecycleManager, ClassLoader," + "ExpressionManager, EndpointFactory, MuleClient, SystemExceptionHandler, SecurityManager, WorkManager, Registry"); } else {// w w w. j a v a 2 s .co m boolean found = false; for (ExecutableElement method : typeElement.getMethods()) { if (method.getSimpleName().toString() .equals("set" + StringUtils.capitalize(variable.getSimpleName().toString()))) { found = true; break; } } if (!found) { throw new ValidationException(variable, "Cannot find a setter method for " + variable.getSimpleName().toString() + " but its being marked as injectable."); } if (variable.asType().toString().equals(ObjectStore.class.getName())) { boolean getterFound = false; for (ExecutableElement method : typeElement.getMethods()) { if (method.getSimpleName().toString() .equals("get" + StringUtils.capitalize(variable.getSimpleName().toString()))) { getterFound = true; break; } } if (!getterFound) { throw new ValidationException(variable, "Cannot find a getter method for " + variable.getSimpleName().toString() + " but its being marked as an injectable Object Store."); } } } } }
From source file:org.netbeans.jcode.core.util.JavaSourceHelper.java
public static MethodTree getMethodByName(CompilationController controller, String methodName) { TypeElement classElement = getTopLevelClassElement(controller); if (classElement == null) { return null; }//from ww w. j av a 2 s . com List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements()); List<MethodTree> found = new ArrayList<MethodTree>(); for (ExecutableElement method : methods) { if (method.getSimpleName().toString().equals(methodName)) { found.add(controller.getTrees().getTree(method)); } } if (found.size() > 1) { throw new IllegalArgumentException("Unexpected overloading methods of '" + methodName + "' found."); } else if (found.size() == 1) { return found.get(0); } return null; }
From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java
public static MethodTree getMethodByName(CompilationController controller, String methodName) { TypeElement classElement = getTopLevelClassElement(controller); if (classElement == null) { return null; }// www .j a va 2s. c o m List<ExecutableElement> methods = ElementFilter.methodsIn(classElement.getEnclosedElements()); List<MethodTree> found = new ArrayList<>(); for (ExecutableElement method : methods) { if (method.getSimpleName().toString().equals(methodName)) { found.add(controller.getTrees().getTree(method)); } } if (found.size() > 1) { throw new IllegalArgumentException("Unexpected overloading methods of '" + methodName + "' found."); } else if (found.size() == 1) { return found.get(0); } return null; }