forked from facebook/buck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This allows annotating an Immutable with AddsToRuleKey. This Immutable can then annotate methods with AddToRuleKey. When constructing the rulekey, the annotated methods will be called and the return value will be added to the rulekey. AddToRuleKey can only be used on methods within an Immutable. This primarily meant as a method to move Immutables off of the deprecated RuleKeyAppendable. Test Plan: CI Reviewed By: jkeljo fbshipit-source-id: 10120ed
- Loading branch information
1 parent
496ed1c
commit 647e369
Showing
10 changed files
with
324 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/com/facebook/buck/rules/keys/ValueMethodValueExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2016-present Facebook, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.facebook.buck.rules.keys; | ||
|
||
import com.google.common.base.Preconditions; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import javax.annotation.Nullable; | ||
|
||
/** Extracts a value of a given field, that is assumed to be accessible. */ | ||
public class ValueMethodValueExtractor implements ValueExtractor { | ||
private final Method method; | ||
|
||
public ValueMethodValueExtractor(Method method) { | ||
Preconditions.checkArgument(method.getParameterCount() == 0); | ||
Preconditions.checkArgument(!method.getReturnType().equals(Void.class)); | ||
// TODO(cjhopman): Should this do any other verification of the signature/annotations on the | ||
// method? | ||
this.method = method; | ||
} | ||
|
||
@Override | ||
public String getFullyQualifiedName() { | ||
return method.getDeclaringClass() + "." + method.getName(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return method.getName(); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public Object getValue(Object obj) { | ||
try { | ||
return method.invoke(obj); | ||
} catch (IllegalAccessException | InvocationTargetException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.