本文整理匯總了Java中org.aikodi.chameleon.core.reference.CrossReference類的典型用法代碼示例。如果您正苦於以下問題:Java CrossReference類的具體用法?Java CrossReference怎麽用?Java CrossReference使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CrossReference類屬於org.aikodi.chameleon.core.reference包,在下文中一共展示了CrossReference類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: analyze
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
@Override
public void analyze(AssignmentExpression assignment) throws LookupException {
Verification result = Valid.create();
Method method = assignment.nearestAncestor(Method.class);
Java7 language = method.language(Java7.class);
if(method != null && Predicates.EXTERNALLY_ACCESSIBLE.eval(method)) {
Variable v = assignment.variable();
if(v instanceof RegularMemberVariable && v.isTrue(language.INSTANCE)) {
Expression e = assignment.getValue();
if(e instanceof CrossReference) {
Declaration rhs = ((CrossReference) e).getElement();
if(rhs instanceof FormalParameter) {
Type type_of_value = ((FormalParameter)rhs).getType();
if((!Predicates.IMMUTABLE_COLLECTION.eval(type_of_value)) && Predicates.COLLECTION.eval(type_of_value)) {
result = result.and(new IncomingCollectionEncapsulationViolationResult(v,(FormalParameter) rhs));
}
}
}
}
}
setResult(result().and(result));
}
示例2: analyze
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
/**
* @{inheritDoc}
*/
@Override
protected void analyze(ReturnStatement statement) throws LookupException {
Verification result = Valid.create();
Method nearestAncestor = statement.nearestAncestor(Method.class);
if(nearestAncestor != null &&
Predicates.EXTERNALLY_ACCESSIBLE.eval(nearestAncestor)) {
Expression expr = statement.getExpression();
if(expr instanceof CrossReference) {
Declaration declaration = ((CrossReference) expr).getElement();
Java7 language = statement.language(Java7.class);
if(declaration instanceof RegularMemberVariable && declaration.isTrue(language.INSTANCE)) {
Type type = ((RegularMemberVariable) declaration).getType();
if((!Predicates.IMMUTABLE_COLLECTION.eval(type)) && Predicates.COLLECTION.eval(type)) {
result = new OutgoingCollectionEncapsulationViolation(nearestAncestor, (Variable) declaration);
}
}
}
}
setResult(result().and(result));
}
示例3: crossReferenceHierarchyFilter
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
protected UniversalPredicate<CrossReference,Nothing> crossReferenceHierarchyFilter(final AnalysisOptions options, final ObjectOrientedView view) throws LookupException {
final UniversalPredicate<Type, Nothing> hierarchyPredicate = hierarchyPredicate(options, view);
UniversalPredicate<CrossReference,LookupException> unguarded = new UniversalPredicate<CrossReference,LookupException>(CrossReference.class) {
@Override
public boolean uncheckedEval(CrossReference object) throws LookupException{
Declaration element = object.getElement();
Type t = element.lexical().nearestAncestorOrSelf(Type.class);
if(t != null) {
return hierarchyPredicate.eval(t);
} else {
return true;
}
}
};
UniversalPredicate<CrossReference, Nothing> result = unguarded.guard(true);
return result;
}
示例4: crossReferenceTargetType
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
protected UniversalPredicate<CrossReference,Nothing> crossReferenceTargetType(final AnalysisOptions options, final ObjectOrientedView view) throws LookupException {
final UniversalPredicate<Type, Nothing> targetPredicate = targetTypePredicate(options, view);
UniversalPredicate<CrossReference,LookupException> unguarded = new UniversalPredicate<CrossReference,LookupException>(CrossReference.class) {
@Override
public boolean uncheckedEval(CrossReference object) throws LookupException{
Declaration element = object.getElement();
Type t = element.lexical().nearestAncestorOrSelf(Type.class);
if(t != null) {
return targetPredicate.eval(t);
} else {
return true;
}
}
};
UniversalPredicate<CrossReference, Nothing> result = unguarded.guard(true);
return result;
}
示例5: noSuperTypes
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
private PredicateSelector<? super Dependency<? super Element, ? super CrossReference, ? super Declaration>> noSuperTypes() {
return new CheckboxPredicateSelector<Dependency<?,?,?>>(
new UniversalPredicate<Dependency, Nothing>(Dependency.class) {
@Override
public boolean uncheckedEval(Dependency t) throws Nothing {
Element target = (Element) t.target();
Element source = (Element)t.source();
if(source instanceof Type && target instanceof Type) {
try {
return ! ((Type)source).subtypeOf((Type) target);
} catch (LookupException e) {
}
}
return true;
}
}, "Ignore super types",true);
}
示例6: crossReferenceNonInheritanceFilter
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
protected UniversalPredicate<CrossReference<?>,Nothing> crossReferenceNonInheritanceFilter() {
return new UniversalPredicate(CrossReference.class) {
@Override
public boolean uncheckedEval(Object object) {
return ((CrossReference)object).nearestAncestor(InheritanceRelation.class) == null;
}
};
}
示例7: uncheckedEval
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
@Override
public boolean uncheckedEval(CrossReference object) {
Declaration d;
try {
d = ((CrossReference<?>)object).getElement();
return d.view().isSource(d);
} catch(Exception e) {
return true;
}
}
示例8: JavaDependencyAnalyzer
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
public JavaDependencyAnalyzer(Project project,
UniversalPredicate<Type,Nothing> sourcePredicate,
UniversalPredicate<? super CrossReference<?>,Nothing> crossReferencePredicate,
UniversalPredicate<Type,Nothing> targetPredicate) {
super(project);
Contracts.notNull(sourcePredicate, "The source predicate cannot be null");
Contracts.notNull(crossReferencePredicate, "The cross reference predicate cannot be null");
_sourcePredicate = sourcePredicate;
_crossReferencePredicate = crossReferencePredicate;
_targetPredicate = targetPredicate;
}
示例9: noDescendants
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
private PredicateSelector<? super Dependency<? super Element, ? super CrossReference, ? super Declaration>> noDescendants() {
return new CheckboxPredicateSelector<Dependency<?,?,?>>(
new UniversalPredicate<Dependency, Nothing>(Dependency.class) {
@Override
public boolean uncheckedEval(Dependency t) throws Nothing {
return ! ((Element) t.target()).hasAncestor((Element)t.source());
}
}, "Ignore lexical descendants",false);
}
示例10: process
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
public boolean process(Dependency<Element, CrossReference, Declaration> dependency, DependencyResult result) {
final Container container = new Container();
final Element newSource = dependency.source();
final Element newTarget = dependency.target();
result.<Nothing>filter(object -> {
try {
if(container.add == false) {
return true;
}
Element oldSource = ((UniEdge<Element>) object).startNode()
.object();
Element oldTarget = ((UniEdge<Element>) object).endNode().object();
if (newSource instanceof Type && oldSource instanceof Type
&& newTarget instanceof Type && oldTarget instanceof Type) {
Type newSourceType = (Type) newSource;
Type newTargetType = (Type) newTarget;
Type oldSourceType = (Type) oldSource;
Type oldTargetType = (Type) oldTarget;
// We first check if the new dependency is redundant.
// That way, if we reach the else branch, we now
// for sure that we can remove the old dependency
// if the second branch is executed.
if(newSourceType != oldSourceType) {
if (newSourceType.subtypeOf(oldSourceType) && oldTargetType.subtypeOf(newTargetType)) {
container.add = false;
return true;
} else if(oldSourceType.subtypeOf(newSourceType) && newTargetType.subtypeOf(oldTargetType)) {
return false;
}
}
}
return true;
} catch (LookupException e) {
return true;
}
});
return container.add;
}
示例11: variable
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
@Override
public Variable variable() throws LookupException {
final Expression var = variableExpression();
if(var instanceof ArrayAccessExpression) {
ArrayAccessExpression a = (ArrayAccessExpression) var;
return (Variable) ((CrossReference)a.getTarget()).getElement();
} else {
return super.variable();
}
}
示例12: erasedReference
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public JavaTypeReference erasedReference() {
JavaTypeReference result = null;
CrossReferenceTarget target = getTarget();
if(target instanceof CrossReference) {
CrossReference<? extends Declaration> erasure = language(Java7.class).erasure((CrossReference)target);
result = new BasicJavaTypeReference(erasure, name());
} else if (target == null) {
result = new BasicJavaTypeReference(null, name());
}
return result;
}
示例13: analyze
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
@Override
protected void analyze(AssignmentExpression assignment) throws LookupException {
Verification result = Valid.create();
final Method method = assignment.nearestAncestor(Method.class);
if(method != null && method.isTrue(method.language(Java7.class).PUBLIC)) {
Variable v = assignment.variable();
if(v instanceof RegularMemberVariable) {
Expression e = assignment.getValue();
if(e instanceof CrossReference) {
final Declaration rhs = ((CrossReference) e).getElement();
if(rhs instanceof FormalParameter) {
Type booleanType = assignment.view(JavaView.class).primitiveType("boolean");
if(! ((FormalParameter) rhs).getType().sameAs(booleanType)) {
boolean notMentioned = true;
Statement stat = assignment.lexical().farthestAncestor(new UniversalPredicate<Statement,Nothing>(Statement.class) {
@Override
public boolean uncheckedEval(Statement s) {
// If s.parent() == the implementation object, then we have reached the
// block of the implementation, so we have to stop before that to object
// the child statement of the block of the implementation
return (! (s.parent() instanceof Implementation)) && s.nearestAncestor(Method.class) == method;
}
});
Block b = (Block) stat.parent();
List<Statement> befores = b.statementsBefore(stat);
for(Statement before : befores) {
List<CrossReference> crefs = before.descendants(CrossReference.class, cref -> cref.getElement().sameAs(rhs));
if(! crefs.isEmpty()) {
notMentioned = false;
}
}
if(notMentioned) {
result = new NonDefensiveFieldAssignmentResult((FormalParameter)rhs,v);
}
}
}
}
}
}
setResult(result().and(result));
}
示例14: crossReferenceSourceFilter
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
protected UniversalPredicate<CrossReference<?>,Nothing> crossReferenceSourceFilter() {
// return new True<>();
return (UniversalPredicate) new IsSource();
}
示例15: IsSource
import org.aikodi.chameleon.core.reference.CrossReference; //導入依賴的package包/類
protected IsSource() {
super(CrossReference.class);
}