Skip to content

Commit

Permalink
Rename local variables and clean up some code (#766)
Browse files Browse the repository at this point in the history
Co-authored-by: Werner Dietl <wdietl@gmail.com>
  • Loading branch information
Ao-senXiong and wmdietl authored May 31, 2024
1 parent dad55e6 commit 97503e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,28 @@ protected void checkThisOrSuperConstructorCall(
@Override
protected boolean commonAssignmentCheck(
Tree varTree,
ExpressionTree valueExp,
ExpressionTree valueExpTree,
@CompilerMessageKey String errorKey,
Object... extraArgs) {
// field write of the form x.f = y
if (TreeUtils.isFieldAccess(varTree)) {
// cast is safe: a field access can only be an IdentifierTree or MemberSelectTree
ExpressionTree lhs = (ExpressionTree) varTree;
ExpressionTree y = valueExp;
VariableElement el = TreeUtils.variableElementFromUse(lhs);
AnnotatedTypeMirror xType = atypeFactory.getReceiverType(lhs);
AnnotatedTypeMirror yType = atypeFactory.getAnnotatedType(y);
AnnotatedTypeMirror lhsReceiverType = atypeFactory.getReceiverType(lhs);
AnnotatedTypeMirror valueExpType = atypeFactory.getAnnotatedType(valueExpTree);
// the special FBC rules do not apply if there is an explicit
// UnknownInitialization annotation
AnnotationMirrorSet fieldAnnotations =
atypeFactory.getAnnotatedType(el).getAnnotations();
if (!AnnotationUtils.containsSameByName(
fieldAnnotations, atypeFactory.UNKNOWN_INITIALIZATION)) {
if (!ElementUtils.isStatic(el)
&& !(atypeFactory.isInitialized(yType)
|| atypeFactory.isUnderInitialization(xType)
|| atypeFactory.isFbcBottom(yType))) {
&& !(atypeFactory.isInitialized(valueExpType)
|| atypeFactory.isUnderInitialization(lhsReceiverType)
|| atypeFactory.isFbcBottom(valueExpType))) {
@CompilerMessageKey String err;
if (atypeFactory.isInitialized(xType)) {
if (atypeFactory.isInitialized(lhsReceiverType)) {
err = COMMITMENT_INVALID_FIELD_WRITE_INITIALIZED;
} else {
err = COMMITMENT_INVALID_FIELD_WRITE_UNKNOWN_INITIALIZATION;
Expand All @@ -155,7 +154,7 @@ protected boolean commonAssignmentCheck(
}
}
}
return super.commonAssignmentCheck(varTree, valueExp, errorKey, extraArgs);
return super.commonAssignmentCheck(varTree, valueExpTree, errorKey, extraArgs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ public static TypeElement toplevelEnclosingTypeElement(Element element) {
public static PackageElement enclosingPackage(Element elem) {
Element result = elem;
while (result != null && result.getKind() != ElementKind.PACKAGE) {
Element encl = result.getEnclosingElement();
result = encl;
result = result.getEnclosingElement();
}
return (PackageElement) result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ private TreeUtils() {
TREEMAKER_SELECT =
TreeMaker.class.getMethod("Select", JCExpression.class, Symbol.class);
} catch (NoSuchMethodException e) {
Error err = new AssertionError("Unexpected error in TreeUtils static initializer");
err.initCause(e);
throw err;
throw new AssertionError("Unexpected error in TreeUtils static initializer", e);
}
}

Expand Down

0 comments on commit 97503e1

Please sign in to comment.