List of usage examples for com.google.common.collect Iterables getLast
public static <T> T getLast(Iterable<T> iterable)
From source file:org.eclipse.xtend.core.jvmmodel.AnonymousClassUtil.java
public JvmGenericType getSuperType(AnonymousClass anonymousClass) { JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor(); if (constructor != null && !constructor.eIsProxy()) { JvmDeclaredType declaringType = constructor.getDeclaringType(); JvmType superType = Iterables.getLast(declaringType.getSuperTypes()).getType(); if (superType instanceof JvmGenericType) return (JvmGenericType) superType; }/*from w ww .j ava2 s. c o m*/ return null; }
From source file:com.google.errorprone.bugpatterns.MultiVariableDeclaration.java
private Description checkDeclarations(List<? extends Tree> children, VisitorState state) { PeekingIterator<Tree> it = Iterators.<Tree>peekingIterator(children.iterator()); while (it.hasNext()) { if (it.peek().getKind() != Tree.Kind.VARIABLE) { it.next();/*from www.java 2 s.c om*/ continue; } VariableTree variableTree = (VariableTree) it.next(); ArrayList<VariableTree> fragments = new ArrayList<>(); fragments.add(variableTree); // Javac handles multi-variable declarations by lowering them in the parser into a series of // individual declarations, all of which have the same start position. We search for the first // declaration in the group, which is either the first variable declared in this scope or has // a distinct end position from the previous declaration. while (it.hasNext() && it.peek().getKind() == Tree.Kind.VARIABLE && ((JCTree) variableTree).getStartPosition() == ((JCTree) it.peek()).getStartPosition()) { fragments.add((VariableTree) it.next()); } if (fragments.size() == 1) { continue; } Fix fix = SuggestedFix.replace(((JCTree) fragments.get(0)).getStartPosition(), state.getEndPosition(Iterables.getLast(fragments)), Joiner.on("; ").join(fragments) + ";"); state.reportMatch(describeMatch(fragments.get(0), fix)); } return NO_MATCH; }
From source file:org.sosy_lab.cpachecker.cpa.value.symbolic.refiner.ARGTreePrecisionUpdater.java
private VariableTrackingPrecision mergeValuePrecisionsForSubgraph(final ARGState pRefinementRoot, final ARGReachedSet pReached) { // get all unique precisions from the subtree Set<VariableTrackingPrecision> uniquePrecisions = Sets.newIdentityHashSet(); for (ARGState descendant : getNonCoveredStatesInSubgraph(pRefinementRoot)) { uniquePrecisions.add(extractValuePrecision(pReached, descendant)); }/*from w ww. java 2 s.c o m*/ // join all unique precisions into a single precision VariableTrackingPrecision mergedPrecision = Iterables.getLast(uniquePrecisions); for (VariableTrackingPrecision precision : uniquePrecisions) { mergedPrecision = mergedPrecision.join(precision); } return mergedPrecision; }
From source file:com.google.devtools.moe.client.testing.DummyRevisionHistory.java
@Override public Revision findHighestRevision(String revId) { if (Strings.isNullOrEmpty(revId)) { // Search for head revision if (commits().isEmpty()) { // if permissive, support legacy tests with an assumed revision. if (permissive()) { return Revision.create("1", name()); } else { return null; }/*w ww . java 2 s . c om*/ } else { // Construct head revision from head commit. return Revision.create(Iterables.getLast(commits()).id(), name()); } } if (indexedCommits().containsKey(revId)) { return Revision.create(revId, name()); } // if permissive, support legacy tests with an assumed revision. return (permissive()) ? Revision.create(revId, name()) : null; }
From source file:com.facebook.presto.util.IterableTransformer.java
public E last() { return Iterables.getLast(iterable); }
From source file:com.github.fommil.netlib.generator.NativeImplJniGenerator.java
private String render(Method method, boolean offsets) { ST f = jniTemplates.getInstanceOf("function"); f.add("returns", jType2C(method.getReturnType())); f.add("fqn", (implementing + "." + method.getName()).replace(".", "_") + (offsets ? "_1offsets" : "")); f.add("name", prefix + method.getName() + suffix); List<String> params = getNetlibCParameterTypes(method, offsets); List<String> names = getNetlibJavaParameterNames(method, offsets); f.add("paramTypes", params); f.add("paramNames", names); f.add("params", getCMethodParams(method, offsets)); if (method.getReturnType() == Void.TYPE) { if (lapacke_hack && Iterables.getLast(names).equals("info")) { f.add("assignReturn", "int returnValue = "); } else {/*from ww w . ja va 2 s . c om*/ f.add("assignReturn", ""); } f.add("return", ""); } else { f.add("assignReturn", jType2C(method.getReturnType()) + " returnValue = "); f.add("return", "return returnValue;"); } List<String> init = Lists.newArrayList(); List<String> clean = Lists.newArrayList(); for (int i = 0; i < params.size(); i++) { String param = params.get(i); String name = names.get(i); ST before = jniTemplates.getInstanceOf(param + "_init"); if (lapacke_hack && name.equals("info")) before = jniTemplates.getInstanceOf(param + "_info_init"); if (before != null) { before.add("name", name); init.add(before.render()); } ST after = jniTemplates.getInstanceOf(param + "_clean"); if (lapacke_hack && name.equals("info")) after = jniTemplates.getInstanceOf(param + "_info_clean"); if (after != null) { after.add("name", name); clean.add(after.render()); } } Collections.reverse(clean); f.add("init", init); f.add("clean", clean); return f.render(); }
From source file:com.facebook.buck.jvm.java.ClasspathChecker.java
/** * Parses a Java classpath string ("path/to/foo:baz.jar:blech.zip:path/to/*") * and checks if at least one entry is valid (exists on disk). * * From http://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html : * * Class path entries can contain the basename wildcard character *, * which is considered equivalent to specifying a list of all the * files in the directory with the extension .jar or .JAR. For * example, the class path entry foo/* specifies all JAR files in the * directory named foo. A classpath entry consisting simply of * * expands to a list of all the jar files in the current directory. *//*from w w w.ja v a 2 s. co m*/ public boolean validateClasspath(String classpath) { for (String entry : Splitter.on(pathSeparator).split(classpath)) { // On Windows, Path.endsWith("*") throws an error: // // java.nio.file.InvalidPathException: Illegal char <*> at index 0 // // So, we split manually. List<String> classpathComponents = Splitter.on(separator).splitToList(entry); if (classpathComponents.isEmpty()) { continue; } if (Iterables.getLast(classpathComponents).equals("*")) { // Trim the * off the path. List<String> dirComponents = classpathComponents.subList(0, classpathComponents.size() - 1); Path entryDir = toPathFunc.apply(Joiner.on(separator).join(dirComponents)); if (!Iterables.isEmpty(globberFunc.apply(entryDir, "*.jar"))) { return true; } else if (!Iterables.isEmpty(globberFunc.apply(entryDir, "*.JAR"))) { return true; } } else { Path entryPath = toPathFunc.apply(entry); if (isDirectoryFunc.apply(entryPath)) { return true; } else if (isFileFunc.apply(entryPath) && ALLOWED_EXTENSIONS_SET.contains( com.google.common.io.Files.getFileExtension(entryPath.toString().toLowerCase(Locale.US)))) { return true; } } } return false; }
From source file:org.eclipse.che.plugin.svn.ide.importer.SubversionProjectImporterPresenter.java
/** {@inheritDoc} */ @Override/*from ww w. java 2 s. c o m*/ public void onProjectUrlChanged(final String projectUrl) { if (ignoreChanges) { return; } final String calcUrl = getUrl(projectUrl, view.getProjectRelativePath()); dataObject.getSource().setLocation(calcUrl); if (isSubversionUrlCorrect(calcUrl)) { view.setProjectUrlErrorHighlight(false); view.setURLErrorMessage(null); if (isNullOrEmpty(view.getProjectName())) { final String projectName = Iterables.getLast(Splitter.on("/").omitEmptyStrings().split(projectUrl)); if (!isNullOrEmpty(projectName)) { view.setProjectName(projectName); dataObject.setName(view.getProjectName()); } } } else { view.setProjectUrlErrorHighlight(true); view.setURLErrorMessage(constants.importProjectUrlIncorrectMessage()); } updateDelegate.updateControls(); }
From source file:org.kitesdk.data.spi.filesystem.PathConversion.java
public String valueStringForDirname(String name) { try {//from www . j a va 2 s . c o m return URLDecoder.decode(Iterables.getLast(PART_SEP.split(name)), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new AssertionError("Unable to find UTF-8 encoding."); } }
From source file:com.squareup.javapoet.ClassName.java
/** Returns the simple name of this class, like {@code "Entry"} for {@link Map.Entry}. */ public String simpleName() { return Iterables.getLast(names); }