Java Code Examples for javax.lang.model.element.Modifier#PRIVATE

The following examples show how to use javax.lang.model.element.Modifier#PRIVATE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityGenerator.java    From requery with Apache License 2.0 6 votes vote down vote up
private Modifier[] generatedMemberModifiers(Modifier... modifiers) {
    Modifier visibility = null;
    switch (entity.propertyVisibility()) {
        case PUBLIC:
            visibility = Modifier.PUBLIC;
            break;
        case PRIVATE:
            if (entity.isEmbedded()) {
                visibility = Modifier.PROTECTED;
            } else {
                visibility = Modifier.PRIVATE;
            }
            break;
        case PACKAGE:
            break;
    }
    ArrayList<Modifier> list = new ArrayList<>();
    if (visibility != null) {
        list.add(visibility);
    }
    Collections.addAll(list, modifiers);
    return list.toArray(new Modifier[list.size()]);
}
 
Example 2
Source File: Initializer.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
public static void initMapper(TypeSpec.Builder builder, String name, VavrModule.Settings settings) {
    Modifier[] mods = new Modifier[] { Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL };
    if (settings != null) {
        builder.addField(FieldSpec.builder(ClassName.get(VavrModule.Settings.class), name + "_SETTINGS", mods)
                .initializer("new $T()\n        .useOptionInPlainFormat($L).deserializeNullAsEmptyCollection($L)",
                        ClassName.get(VavrModule.Settings.class),
                        settings.useOptionInPlainFormat(), settings.deserializeNullAsEmptyCollection())
                .build());
        builder.addField(FieldSpec.builder(ClassName.get(VavrModule.class), name + "_MODULE", mods)
                .initializer("new $T($L)", ClassName.get(VavrModule.class), name + "_SETTINGS")
                .build());
    } else {
        builder.addField(FieldSpec.builder(ClassName.get(VavrModule.class), name + "_MODULE", mods)
                .initializer("new $T()", ClassName.get(VavrModule.class))
                .build());
    }
    builder.addField(FieldSpec.builder(ClassName.get(ObjectMapper.class), name, mods)
            .initializer("new $T().registerModule($L)", ClassName.get(ObjectMapper.class), name + "_MODULE")
            .build());
}
 
Example 3
Source File: ProcessingUtils.java    From aircon with MIT License 5 votes vote down vote up
public static Modifier getVisibilityModifier(Element element) {
	switch (Visibility.ofElement(element)) {
		case PRIVATE:
			return Modifier.PRIVATE;
		case PROTECTED:
			return Modifier.PROTECTED;
		case PUBLIC:
			return Modifier.PUBLIC;
	}

	return null;
}
 
Example 4
Source File: ModifierOrderer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
     * Returns the {@link Modifier} for the given token kind, or {@code
     * null}.
     */
    private static Modifier getModifier(TokenKind kind) {
        if (kind == null) {
            return null;
        }
        switch (kind) {
            case PUBLIC:
                return Modifier.PUBLIC;
            case PROTECTED:
                return Modifier.PROTECTED;
            case PRIVATE:
                return Modifier.PRIVATE;
            case ABSTRACT:
                return Modifier.ABSTRACT;
            case STATIC:
                return Modifier.STATIC;
            // TODO: 22-Jul-17 unsupported lambdas expr
//            case DEFAULT:
//                return Modifier.DEFAULT;
            case FINAL:
                return Modifier.FINAL;
            case TRANSIENT:
                return Modifier.TRANSIENT;
            case VOLATILE:
                return Modifier.VOLATILE;
            case SYNCHRONIZED:
                return Modifier.SYNCHRONIZED;
            case NATIVE:
                return Modifier.NATIVE;
            case STRICTFP:
                return Modifier.STRICTFP;
            default:
                return null;
        }
    }
 
Example 5
Source File: PsiModifierExtractor.java    From litho with Apache License 2.0 5 votes vote down vote up
private static Modifier psiModifierToModifier(PsiElement psiModifier) {
  switch (psiModifier.getText()) {
    case PsiModifier.ABSTRACT:
      return Modifier.ABSTRACT;
    case PsiModifier.FINAL:
      return Modifier.FINAL;
    case PsiModifier.NATIVE:
      return Modifier.NATIVE;
    case PsiModifier.PRIVATE:
      return Modifier.PRIVATE;
    case PsiModifier.PROTECTED:
      return Modifier.PROTECTED;
    case PsiModifier.PUBLIC:
      return Modifier.PUBLIC;
    case PsiModifier.STATIC:
      return Modifier.STATIC;
    case PsiModifier.STRICTFP:
      return Modifier.STRICTFP;
    case PsiModifier.SYNCHRONIZED:
      return Modifier.SYNCHRONIZED;
    case PsiModifier.TRANSIENT:
      return Modifier.TRANSIENT;
    case PsiModifier.VOLATILE:
      return Modifier.VOLATILE;
    default:
      // TODO better error message, ideally w/ line number
      throw new ComponentsProcessingException(
          "Unexpected Modifier, modifier is: " + psiModifier.getText());
  }
}
 
Example 6
Source File: DelegateMethodDescriptionTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuilder() {
  ImmutableList<AnnotationSpec> annotations =
      ImmutableList.of(AnnotationSpec.builder(Override.class).build());
  Modifier accessType = Modifier.PRIVATE;
  TypeName returnType = ClassName.bestGuess("ClassName");
  String name = "test";
  ImmutableList<TypeName> parameterTypes =
      ImmutableList.<TypeName>of(ClassName.bestGuess("ParameterType"));
  ImmutableList<TypeName> exceptions =
      ImmutableList.<TypeName>of(ClassName.bestGuess("ExceptionType"));
  ImmutableList<OptionalParameterType> optionalParameterTypes = ImmutableList.of(PROP, STATE);

  DelegateMethodDescription delegateMethodDescription =
      DelegateMethodDescription.newBuilder()
          .annotations(annotations)
          .accessType(accessType)
          .returnType(returnType)
          .name(name)
          .definedParameterTypes(parameterTypes)
          .optionalParameterTypes(optionalParameterTypes)
          .exceptions(exceptions)
          .build();

  assertThat(delegateMethodDescription.accessType).isEqualTo(accessType);
  assertThat(delegateMethodDescription.returnType).isEqualTo(returnType);
  assertThat(delegateMethodDescription.name).isEqualTo(name);
  assertThat(delegateMethodDescription.annotations).isSameAs(annotations);
  assertThat(delegateMethodDescription.definedParameterTypes).isSameAs(parameterTypes);
  assertThat(delegateMethodDescription.optionalParameterTypes).isSameAs(optionalParameterTypes);
  assertThat(delegateMethodDescription.exceptions).isSameAs(exceptions);
}
 
Example 7
Source File: ModifierOrderer.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
     * Returns the {@link Modifier} for the given token kind, or {@code
     * null}.
     */
    private static Modifier getModifier(TokenKind kind) {
        if (kind == null) {
            return null;
        }
        switch (kind) {
            case PUBLIC:
                return Modifier.PUBLIC;
            case PROTECTED:
                return Modifier.PROTECTED;
            case PRIVATE:
                return Modifier.PRIVATE;
            case ABSTRACT:
                return Modifier.ABSTRACT;
            case STATIC:
                return Modifier.STATIC;
            // TODO: 22-Jul-17 unsupported lambdas expr
//            case DEFAULT:
//                return Modifier.DEFAULT;
            case FINAL:
                return Modifier.FINAL;
            case TRANSIENT:
                return Modifier.TRANSIENT;
            case VOLATILE:
                return Modifier.VOLATILE;
            case SYNCHRONIZED:
                return Modifier.SYNCHRONIZED;
            case NATIVE:
                return Modifier.NATIVE;
            case STRICTFP:
                return Modifier.STRICTFP;
            default:
                return null;
        }
    }
 
Example 8
Source File: ModifierOrderer.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link javax.lang.model.element.Modifier} for the given token kind, or {@code
 * null}.
 */
private static Modifier getModifier(TokenKind kind) {
  if (kind == null) {
    return null;
  }
  switch (kind) {
    case PUBLIC:
      return Modifier.PUBLIC;
    case PROTECTED:
      return Modifier.PROTECTED;
    case PRIVATE:
      return Modifier.PRIVATE;
    case ABSTRACT:
      return Modifier.ABSTRACT;
    case STATIC:
      return Modifier.STATIC;
    case DEFAULT:
      return Modifier.DEFAULT;
    case FINAL:
      return Modifier.FINAL;
    case TRANSIENT:
      return Modifier.TRANSIENT;
    case VOLATILE:
      return Modifier.VOLATILE;
    case SYNCHRONIZED:
      return Modifier.SYNCHRONIZED;
    case NATIVE:
      return Modifier.NATIVE;
    case STRICTFP:
      return Modifier.STRICTFP;
    default:
      return null;
  }
}
 
Example 9
Source File: VisibilityChanged.java    From revapi with Apache License 2.0 5 votes vote down vote up
private Modifier getVisibility(Element t) {
    for (Modifier m : t.getModifiers()) {
        if (m == Modifier.PUBLIC || m == Modifier.PROTECTED || m == Modifier.PRIVATE) {
            return m;
        }
    }

    return null;
}
 
Example 10
Source File: BindSharedPreferencesBuilder.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * Generate shared preference manager.
 *
 * @param elementUtils
 *            the element utils
 * @param filer
 *            the filer
 * @param entity
 *            the entity
 * @return typeName of generated class
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static String generate(Elements elementUtils, Filer filer, PrefsEntity entity) throws IOException {
	com.abubusoft.kripton.common.Converter<String, String> converter = CaseFormat.UPPER_CAMEL.converterTo(CaseFormat.LOWER_CAMEL);
	String beanClassName = entity.getElement().getSimpleName().toString();
	String className = getBuildPreferenceName(entity);
	ModelAnnotation annotation = entity.getAnnotation(BindSharedPreferences.class);
	String sharedPreferenceName = annotation.getAttribute(AnnotationAttributeType.VALUE);
	boolean generateRx = entity.hasRxProperties();
	boolean generateLiveData = entity.hasLiveDataProperties();

	PackageElement pkg = elementUtils.getPackageOf(entity.getElement());
	String packageName = pkg.isUnnamed() ? "" : pkg.getQualifiedName().toString();

	AnnotationProcessorUtilis.infoOnGeneratedClasses(BindSharedPreferences.class, packageName, className);
	// @formatter:off
	builder = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC)
			.superclass(AbstractSharedPreference.class);

	BindTypeContext context = new BindTypeContext(builder, TypeUtility.typeName(entity.getElement()),
			Modifier.PRIVATE);

	// @formatter:on	
	builder.addJavadoc("This class is the shared preference binder defined for $T\n\n", entity.getElement());
	JavadocUtility.generateJavadocGeneratedBy(builder);
	builder.addJavadoc("@see $T\n", entity.getElement());

	if (StringUtils.hasText(sharedPreferenceName)) {
		builder.addField(FieldSpec.builder(String.class, "SHARED_PREFERENCE_NAME", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
				.initializer("$S", converter.convert(entity.getSimpleName().toString())).addJavadoc("shared preferences typeName for $T\n", entity.getElement()).build());
	}

	builder.addField(FieldSpec.builder(className(beanClassName), "defaultBean", Modifier.PRIVATE, Modifier.FINAL).addJavadoc("working instance of bean\n").build());

	{
		MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("edit").addJavadoc("create an editor to modify shared preferences\n").returns(typeName("BindEditor"))
				.addModifiers(Modifier.PUBLIC);
		methodBuilder.addStatement("return new $T()", typeName("BindEditor"));
		builder.addMethod(methodBuilder.build());
	}

	generateEditor(entity);

	generateCreate(sharedPreferenceName, beanClassName, generateRx, generateLiveData);

	generateConstructor(entity, sharedPreferenceName, beanClassName);

	generateRefresh(sharedPreferenceName, className);

	generateRxSupport(sharedPreferenceName, beanClassName, generateRx, entity);

	generateLiveDataSupport(sharedPreferenceName, beanClassName, generateLiveData, entity);

	generateResetMethod(entity);

	generateReadMethod(entity);

	generateWriteMethod(entity);

	generateSingleReadMethod(entity);

	// generate all needed writer and reader
	List<PrefsProperty> fields = entity.getCollection();
	List<PrefsProperty> filteredFields = new ArrayList<>();

	// we need to avoid generation of persists values
	for (PrefsProperty item : fields) {
		if (SetPrefsTransformation.isStringSet(item)) {
			continue;
		} else {
			filteredFields.add(item);
		}
	}

	// avoid to consider StringSet
	ManagedPropertyPersistenceHelper.generateFieldPersistance(context, filteredFields, PersistType.STRING, false, Modifier.PROTECTED);

	generateInstance(className);

	TypeSpec typeSpec = builder.build();
	JavaWriterHelper.writeJava2File(filer, packageName, typeSpec);

	return className;
}