org.jetbrains.uast.UField Java Examples

The following examples show how to use org.jetbrains.uast.UField. 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: InjectedFieldInJobNotTransientDetector.java    From cathode with Apache License 2.0 6 votes vote down vote up
@Override public boolean visitField(UField field) {
  PsiModifierList modifierList = field.getModifierList();
  if (modifierList == null || modifierList.hasModifierProperty(PsiModifier.TRANSIENT)) {
    return false;
  }

  if (!isInJob(field)) {
    return false;
  }

  if (hasAnnotation(modifierList, JAVAX_INJECT)) {
    context.report(ISSUE, context.getLocation(field), LINT_ERROR_MESSAGE);
  }

  return super.visitField(field);
}
 
Example #2
Source File: WrongTypeDefaultValueConfigDetector.java    From aircon with MIT License 6 votes vote down vote up
@Override
protected void visitDefaultConfigAnnotation(final UAnnotation node, final PsiElement defaultConfig) {
	if (!ConfigElementsUtils.isConfigFieldReference(defaultConfig)) {
		return;
	}

	final UField configField = (UField) node.getUastParent();

	final String configFieldType = ConfigElementsUtils.getConfigFieldType(configField);
	if (configFieldType == null) {
		return;
	}
	final String defaultValueConfigFieldType = ConfigElementsUtils.getConfigFieldType(ElementUtils.getReferencedField(defaultConfig));

	if (!configFieldType.equals(defaultValueConfigFieldType)) {
		report(node);
	}
}
 
Example #3
Source File: MultipleConfigsForSameKeyDetector.java    From aircon with MIT License 5 votes vote down vote up
@Override
protected void visitConfigField(final UField node) {
	final String configKey = ElementUtils.getFieldStringConst(node);
	final UField fieldForConfigKey = getFieldForKey(configKey);

	if (fieldForConfigKey != null && !fieldForConfigKey.getName()
	                                                   .equals(node.getName())) {
		report(node, String.format(DESC_FORMAT, configKey, fieldForConfigKey.getName()));
	}
	mVisitedConfigs.add(node);
}
 
Example #4
Source File: DialogExtendLintDetector.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@Override
public void visitClass(JavaContext context, UClass declaration) {
    PsiModifierList classModifiers = declaration.getModifierList();
    if (classModifiers == null || !classModifiers.hasModifierProperty("abstract")) {
        // check for static build method
        boolean hasBuildMethod = false;
        for (PsiMethod method : declaration.getMethods()) {
            if ("build".equals(method.getName()) && method.getModifierList()
                    .hasModifierProperty("static")) {
                hasBuildMethod = true;
                break;
            }
        }
        if (!hasBuildMethod){
            context.report(BUILD_OVERWRITE, context.getLocation(declaration.getExtendsList()),
                    BUILD_OVERWRITE_MESSAGE);
        }

        // check for public static String TAG
        boolean hasTag = false;
        for (UField field : declaration.getFields()) {
            PsiModifierList modifiers = field.getModifierList();
            if ("TAG".equals(field.getName()) && LintUtils.isString(field.getType()) &&
                    modifiers != null && modifiers.hasModifierProperty("public") &&
                    modifiers.hasModifierProperty("static")) {
                hasTag = true;
                break;
            }
        }
        if (!hasTag) {
            context.report(TAG, context.getLocation(declaration.getExtendsList()), TAG_MESSAGE);
        }

    }
}
 
Example #5
Source File: DialogExtendLintDetector.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@Override
public void visitClass(JavaContext context, UClass declaration) {
    PsiModifierList classModifiers = declaration.getModifierList();
    if (classModifiers == null || !classModifiers.hasModifierProperty("abstract")) {
        // check for static build method
        boolean hasBuildMethod = false;
        for (PsiMethod method : declaration.getMethods()) {
            if ("build".equals(method.getName()) && method.getModifierList()
                    .hasModifierProperty("static")) {
                hasBuildMethod = true;
                break;
            }
        }
        if (!hasBuildMethod){
            context.report(BUILD_OVERWRITE, context.getLocation(declaration.getExtendsList()),
                    BUILD_OVERWRITE_MESSAGE);
        }

        // check for public static String TAG
        boolean hasTag = false;
        for (UField field : declaration.getFields()) {
            PsiModifierList modifiers = field.getModifierList();
            if ("TAG".equals(field.getName()) && LintUtils.isString(field.getType()) &&
                    modifiers != null && modifiers.hasModifierProperty("public") &&
                    modifiers.hasModifierProperty("static")) {
                hasTag = true;
                break;
            }
        }
        if (!hasTag) {
            context.report(TAG, context.getLocation(declaration.getExtendsList()), TAG_MESSAGE);
        }

    }
}
 
Example #6
Source File: CyclicConfigGroupValuesDetector.java    From aircon with MIT License 5 votes vote down vote up
@Override
protected void visitConfigGroupAnnotation(final UAnnotation node) {
	final PsiField configField = ((UField) node.getUastParent()).getPsi();
	if (hasCyclicConfigGroupReference(configField, new ArrayList<>(Collections.singletonList(configField)))) {
		report(node);
	}
}
 
Example #7
Source File: CyclicDefaultValueConfigDetector.java    From aircon with MIT License 5 votes vote down vote up
@Override
protected void visitDefaultConfigAnnotation(final UAnnotation node, final PsiElement defaultConfig) {
	final UField configField = (UField) node.getUastParent();

	final boolean cyclicDefaultValueConfigReference = hasCyclicDefaultValueConfigReference(configField, new ArrayList<>(Collections.singletonList(configField.getPsi())));
	if (cyclicDefaultValueConfigReference) {
		report(node);
	}
}
 
Example #8
Source File: DefaultValueIssueDetector.java    From aircon with MIT License 5 votes vote down vote up
@Override
protected final void visitConfigField(final UField node) {
	final boolean defaultValue = ConfigElementsUtils.hasDefaultValueAttribute(node);
	final boolean defaultConfig = ConfigElementsUtils.hasDefaultConfigAnnotation(node);
	final boolean defaultRes = ConfigElementsUtils.hasDefaultResAnnotation(node);

	visitConfigField(node, defaultValue, defaultConfig, defaultRes);
}
 
Example #9
Source File: MissingDefaultValueDetector.java    From aircon with MIT License 5 votes vote down vote up
@Override
protected void visitConfigField(final UField node, final boolean defaultValue, final boolean defaultConfig, final boolean defaultRes) {
	if (ConfigElementsUtils.isConfigGroupField(node.getPsi())) {
		return;
	}
	mConfigElements.add(node);
	if (defaultValue || defaultConfig || defaultRes) {
		mConfigFieldsWithDefaultValues.add(node);
	}
}
 
Example #10
Source File: ConfigFieldIssueDetector.java    From aircon with MIT License 5 votes vote down vote up
@Override
public final void visit(final UField node) {
	if (!ConfigElementsUtils.hasConfigAnnotation(node)) {
		return;
	}
	final PsiAnnotation annotation = ConfigElementsUtils.extractConfigAnnotation(node.getPsi());
	if (ConfigElementsUtils.isConfigGroupAnnotation(annotation)) {
		return;
	}

	visitConfigField(node);
}
 
Example #11
Source File: MultipleConfigAnnotationDetector.java    From aircon with MIT License 5 votes vote down vote up
@Override
public void visit(final UField node) {
	final int configAnnotationsCount = ConfigElementsUtils.getConfigAnnotationsCount(node);

	if (configAnnotationsCount > 1) {
		report(node);
	}
}
 
Example #12
Source File: MissingSourceDetector.java    From aircon with MIT License 5 votes vote down vote up
private LintFix createFix(final UField node) {
	final LintFix.GroupBuilder groupBuilder = LintFix.create()
	                                                 .group();
	groupBuilder.add(addSourceAnnotationFix(node, "field"));
	groupBuilder.add(addSourceAnnotationFix(node.getUastParent(), "feature interface"));
	return groupBuilder.build();
}
 
Example #13
Source File: MultipleConfigsForSameKeyDetector.java    From aircon with MIT License 5 votes vote down vote up
private UField getFieldForKey(String key) {
	for (UField visitedConfig : mVisitedConfigs) {
		if (ElementUtils.getFieldStringConst(visitedConfig)
		                .equals(key)) {
			return visitedConfig;
		}
	}
	return null;
}
 
Example #14
Source File: AirConUsageDetector.java    From aircon with MIT License 5 votes vote down vote up
@Override
public boolean visitField(@NotNull final UField node) {
	for (IssueDetector issueDetector : mIssueDetectors) {
		issueDetector.visit(node);
	}
	return super.visitField(node);
}
 
Example #15
Source File: NonConstFieldDetector.java    From aircon with MIT License 4 votes vote down vote up
@Override
public void visit(final UField node) {
	if (ConfigElementsUtils.hasConfigAnnotation(node.getPsi()) && !ElementUtils.hasConstInitializer(node)) {
		report(node);
	}
}
 
Example #16
Source File: MultipleDefaultValueAttributesDetector.java    From aircon with MIT License 4 votes vote down vote up
@Override
protected void visitConfigField(final UField node, final boolean defaultValue, final boolean defaultConfig, final boolean defaultRes) {
	if ((defaultValue && defaultConfig) || (defaultConfig && defaultRes) || (defaultValue && defaultRes)) {
		report(node);
	}
}
 
Example #17
Source File: InvalidFieldTypeDetector.java    From aircon with MIT License 4 votes vote down vote up
@Override
public void visit(final UField node) {
	if (ConfigElementsUtils.hasConfigAnnotation(node.getPsi()) && !ElementUtils.isString(node.getType())) {
		report(node);
	}
}
 
Example #18
Source File: IssueDetector.java    From aircon with MIT License 4 votes vote down vote up
public void visit(final UField node) {
	// No-op, to be overridden
}
 
Example #19
Source File: ConfigElementsUtils.java    From aircon with MIT License 4 votes vote down vote up
public static UAnnotation getConfigGroupAnnotation(final UField node) {
	return node.findAnnotation(ConfigGroup.class.getCanonicalName());
}
 
Example #20
Source File: ElementUtils.java    From aircon with MIT License 4 votes vote down vote up
public static boolean hasConstInitializer(final @NotNull UField node) {
	final UExpression initializer = node.getUastInitializer();
	return initializer != null && initializer.evaluate() != null;
}
 
Example #21
Source File: ElementUtils.java    From aircon with MIT License 4 votes vote down vote up
public static String getFieldStringConst(final @NotNull UField node) {
	return (String) node.getUastInitializer()
	                    .evaluate();
}
 
Example #22
Source File: MissingSourceDetector.java    From aircon with MIT License 4 votes vote down vote up
@Override
protected void visitConfigField(final UField node) {
	if (!ConfigElementsUtils.hasSourceAnnotation(node) && !ConfigElementsUtils.hasSourceAnnotation(node.getContainingClass())) {
		report(node, createFix(node));
	}
}
 
Example #23
Source File: ConfigFieldIssueDetector.java    From aircon with MIT License votes vote down vote up
protected abstract void visitConfigField(final UField node); 
Example #24
Source File: DefaultValueIssueDetector.java    From aircon with MIT License votes vote down vote up
protected abstract void visitConfigField(final UField node, final boolean defaultValue, final boolean defaultConfig, final boolean defaultRes);