本文整理汇总了Java中com.sun.tools.javac.util.Pair类的典型用法代码示例。如果您正苦于以下问题:Java Pair类的具体用法?Java Pair怎么用?Java Pair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pair类属于com.sun.tools.javac.util包,在下文中一共展示了Pair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitClassDef
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
@Override
public void visitClassDef(JCClassDecl tree) {
TypeSymbol currentClassPrev = currentClass;
currentClass = tree.sym;
List<Pair<TypeSymbol, Symbol>> prevOuterThisStack = outerThisStack;
try {
if (currentClass != null) {
if (currentClass.hasOuterInstance())
outerThisDef(currentClass);
super.visitClassDef(tree);
}
} finally {
outerThisStack = prevOuterThisStack;
currentClass = currentClassPrev;
}
}
示例2: checkThis
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
private void checkThis(DiagnosticPosition pos, TypeSymbol c) {
if (checkThis && currentClass != c) {
List<Pair<TypeSymbol, Symbol>> ots = outerThisStack;
if (ots.isEmpty()) {
log.error(pos, "no.encl.instance.of.type.in.scope", c); //NOI18N
return;
}
Pair<TypeSymbol, Symbol> ot = ots.head;
TypeSymbol otc = ot.fst;
while (otc != c) {
do {
ots = ots.tail;
if (ots.isEmpty()) {
log.error(pos, "no.encl.instance.of.type.in.scope", c); //NOI18N
return;
}
ot = ots.head;
} while (ot.snd != otc);
if (otc.owner.kind != Kinds.Kind.PCK && !otc.hasOuterInstance()) {
log.error(pos, "cant.ref.before.ctor.called", c); //NOI18N
return;
}
otc = ot.fst;
}
}
}
示例3: setOption1
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
private void setOption1(String name, OptionKind kind, Object... args) {
String arg = argsToString(args);
JavacOption option = sharedCompiler.getOption(name);
if (option == null || !match(kind, option.getKind()))
throw new IllegalArgumentException(name);
if ((args.length != 0) != option.hasArg())
throw new IllegalArgumentException(name);
if (option.hasArg()) {
if (option.process(null, name, arg)) // FIXME
throw new IllegalArgumentException(name);
} else {
if (option.process(null, name)) // FIXME
throw new IllegalArgumentException(name);
}
options.add(new Pair<String,String>(name,arg));
}
示例4: getAllValues
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
/**
* Returns a map from element symbols to their values.
* Includes all elements, whether explicit or defaulted.
*/
private Map<MethodSymbol, Attribute> getAllValues() {
Map<MethodSymbol, Attribute> res =
new LinkedHashMap<MethodSymbol, Attribute>();
// First find the default values.
ClassSymbol sym = (ClassSymbol) anno.type.tsym;
for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
if (e.sym.kind == Kinds.MTH) {
MethodSymbol m = (MethodSymbol) e.sym;
Attribute def = m.getDefaultValue();
if (def != null)
res.put(m, def);
}
}
// Next find the explicit values, possibly overriding defaults.
for (Pair<MethodSymbol, Attribute> p : anno.values)
res.put(p.fst, p.snd);
return res;
}
示例5: toString
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
/**
* Returns a string representation of this annotation.
* String is of one of the forms:
* @com.example.foo(name1=val1, name2=val2)
* @com.example.foo(val)
* @com.example.foo
* Omit parens for marker annotations, and omit "value=" when allowed.
*/
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("@");
buf.append(type);
int len = values.length();
if (len > 0) {
buf.append('(');
boolean first = true;
for (Pair<MethodSymbol, Attribute> value : values) {
if (!first) buf.append(", ");
first = false;
Name name = value.fst.name;
if (len > 1 || name != name.table.names.value) {
buf.append(name);
buf.append('=');
}
buf.append(value.snd);
}
buf.append(')');
}
return buf.toString();
}
示例6: getDistAndTimeBetweenPlaces
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
public static Pair<Double, Double> getDistAndTimeBetweenPlaces(Place a, Place b) {
if (a.getAddress() == null || b.getAddress() == null) {
return new Pair<>(Place.getEuclidDistBetweenPlaces(a, b), Place.getTravelTimeBetweenPlaces(a, b));
}
if (Objects.equals(a.getAddress(), b.getAddress())) {
return new Pair<>(0., 0.);
}
JSONObject localDBres = getTDMfromLocalDB(a.getAddress(), b.getAddress());
if (localDBres == null) {
DistanceMatrixApiRequest req = new DistanceMatrixApiRequest(context);
req.origins(a.getAddress());
req.destinations(b.getAddress());
DistanceMatrix result;
try {
result = req.await();
Double dist = (double) result.rows[0].elements[0].distance.inMeters;
Double time = (double) result.rows[0].elements[0].duration.inSeconds;
return new Pair<>(dist, time);
} catch (Exception e) {
e.printStackTrace();
}
return new Pair<>(Double.MAX_VALUE, Double.MAX_VALUE);
} else {
return new Pair<>(Double.parseDouble(String.valueOf(localDBres.get("distance"))), Double.parseDouble(String.valueOf(localDBres.get("time"))));
}
}
示例7: findSource
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
private Pair<JavacTask, CompilationUnitTree> findSource(String moduleName,
String binaryName) throws IOException {
JavaFileObject jfo = fm.getJavaFileForInput(StandardLocation.SOURCE_PATH,
binaryName,
JavaFileObject.Kind.SOURCE);
if (jfo == null)
return null;
List<JavaFileObject> jfos = Arrays.asList(jfo);
JavaFileManager patchFM = moduleName != null
? new PatchModuleFileManager(baseFileManager, jfo, moduleName)
: baseFileManager;
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, patchFM, d -> {}, null, null, jfos);
Iterable<? extends CompilationUnitTree> cuts = task.parse();
task.enter();
return Pair.of(task, cuts.iterator().next());
}
示例8: filterExecutableTypesByArguments
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
private List<Pair<ExecutableElement, ExecutableType>> filterExecutableTypesByArguments(AnalyzeTask at, Iterable<Pair<ExecutableElement, ExecutableType>> candidateMethods, List<TypeMirror> precedingActualTypes) {
List<Pair<ExecutableElement, ExecutableType>> candidate = new ArrayList<>();
int paramIndex = precedingActualTypes.size();
OUTER:
for (Pair<ExecutableElement, ExecutableType> method : candidateMethods) {
boolean varargInvocation = paramIndex >= method.snd.getParameterTypes().size();
for (int i = 0; i < paramIndex; i++) {
TypeMirror actual = precedingActualTypes.get(i);
if (this.parameterType(method.fst, method.snd, i, !varargInvocation)
.noneMatch(formal -> at.getTypes().isAssignable(actual, formal))) {
continue OUTER;
}
}
candidate.add(method);
}
return candidate;
}
示例9: findConstructor
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
private Symbol.MethodSymbol findConstructor( IModule module, String fqn, BasicJavacTask javacTask )
{
manifold.util.Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( module ).getClassSymbol( javacTask, fqn );
Symbol.ClassSymbol cs = classSymbol.getFirst();
Symbol.MethodSymbol ctor = null;
for( Symbol sym : cs.getEnclosedElements() )
{
if( sym instanceof Symbol.MethodSymbol && sym.flatName().toString().equals( "<init>" ) )
{
if( ctor == null )
{
ctor = (Symbol.MethodSymbol)sym;
}
else
{
ctor = mostAccessible( ctor, (Symbol.MethodSymbol)sym );
}
if( Modifier.isPublic( (int)ctor.flags() ) )
{
return ctor;
}
}
}
return ctor;
}
示例10: createMethodCache
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
private Map<String, Element> createMethodCache(String binaryName) throws IOException {
Pair<JavacTask, CompilationUnitTree> source = findSource(binaryName);
if (source == null)
return Collections.emptyMap();
Map<String, Element> signature2Method = new HashMap<>();
Trees trees = Trees.instance(source.fst);
new TreePathScanner<Void, Void>() {
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitMethod(MethodTree node, Void p) {
Element currentMethod = trees.getElement(getCurrentPath());
if (currentMethod != null) {
signature2Method.put(elementHeader(currentMethod, false), currentMethod);
}
return null;
}
}.scan(source.snd, null);
return signature2Method;
}
示例11: findSource
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
private Pair<JavacTask, CompilationUnitTree> findSource(String binaryName) throws IOException {
JavaFileObject jfo = fm.getJavaFileForInput(StandardLocation.SOURCE_PATH,
binaryName,
JavaFileObject.Kind.SOURCE);
if (jfo == null)
return null;
List<JavaFileObject> jfos = Arrays.asList(jfo);
JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, fm, d -> {}, null, null, jfos);
Iterable<? extends CompilationUnitTree> cuts = task.parse();
task.enter();
return Pair.of(task, cuts.iterator().next());
}
示例12: calcAvgRating
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
/**
* @param from_id from userId
* @param rating_t ratings From or To
* @return average rating
*/
public Pair<Double, Integer> calcAvgRating(long from_id, Rating_t rating_t) {
RatingService ratingService = new RatingService();
List<RatingEntity> ratingsLst = ratingService.getFromOrToRatings(from_id, rating_t);
double avg_rating = 0;
int total_reputation = 0;
for (RatingEntity r : ratingsLst) {
total_reputation = updateReputation(total_reputation, r.getRating());
avg_rating += r.getRating();
}
if (ratingsLst.size() <= 0) {
return null;
}
avg_rating /= ratingsLst.size();
return new Pair<>(avg_rating, total_reputation);
}
示例13: visitClass
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
/**
* Calculates difference between {@code minuend} and first component
* of {@code eltPair}, adding results to second component of {@code eltPair}.
*/
@Override
public Void visitClass(AClass minuend, Pair<AElement, AElement> eltPair) {
AClass subtrahend = (AClass) eltPair.fst;
AClass difference = (AClass) eltPair.snd;
visitElements(minuend.bounds, subtrahend.bounds, difference.bounds);
visitElements(minuend.extendsImplements,
subtrahend.extendsImplements, difference.extendsImplements);
visitElements(minuend.methods, subtrahend.methods,
difference.methods);
visitElements(minuend.staticInits, subtrahend.staticInits,
difference.staticInits);
visitElements(minuend.instanceInits, subtrahend.instanceInits,
difference.instanceInits);
visitElements(minuend.fields, subtrahend.fields, difference.fields);
visitElements(minuend.fieldInits, subtrahend.fieldInits,
difference.fieldInits);
return visitDeclaration(minuend, eltPair);
}
示例14: visitExpression
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
/**
* Calculates difference between {@code minuend} and first component
* of {@code eltPair}, adding results to second component of {@code eltPair}.
*/
@Override
public Void visitExpression(AExpression minuend,
Pair<AElement, AElement> eltPair) {
AExpression subtrahend = (AExpression) eltPair.fst;
AExpression difference = (AExpression) eltPair.snd;
visitElements(minuend.typecasts, subtrahend.typecasts,
difference.typecasts);
visitElements(minuend.instanceofs, subtrahend.instanceofs,
difference.instanceofs);
visitElements(minuend.news, subtrahend.news, difference.news);
visitElements(minuend.calls, subtrahend.calls, difference.calls);
visitElements(minuend.refs, subtrahend.refs, difference.refs);
visitElements(minuend.funs, subtrahend.funs, difference.funs);
return visitElement(minuend, eltPair);
}
示例15: visitMethod
import com.sun.tools.javac.util.Pair; //导入依赖的package包/类
/**
* Calculates difference between {@code minuend} and first component
* of {@code eltPair}, adding results to second component of {@code eltPair}.
*/
@Override
public Void visitMethod(AMethod minuend,
Pair<AElement, AElement> eltPair) {
AMethod subtrahend = (AMethod) eltPair.fst;
AMethod difference = (AMethod) eltPair.snd;
visitElements(minuend.bounds, subtrahend.bounds, difference.bounds);
visitElements(minuend.parameters, subtrahend.parameters,
difference.parameters);
visitElements(minuend.throwsException, subtrahend.throwsException,
difference.throwsException);
visitElements(minuend.parameters, subtrahend.parameters,
difference.parameters);
visitBlock(minuend.body,
elemPair(subtrahend.body, difference.body));
if (minuend.returnType != null) {
minuend.returnType.accept(this,
elemPair(subtrahend.returnType, difference.returnType));
}
if (minuend.receiver != null) {
minuend.receiver.accept(this,
elemPair(subtrahend.receiver, difference.receiver));
}
return visitDeclaration(minuend, eltPair);
}