Retrieves a MortarScope from the given context. If none is found, retrieves a MortarScope from
the application context.

@return null if no scope is found in either the given context or the application context
168471
public static MortarScope getScope(Context context) {
    //noinspection ResourceType
    Object scope = context.getSystemService(MORTAR_SERVICE);
    if (scope == null) {
      // Essentially a workaround for the lifecycle interval where an Activity's
      // base context is not yet set to the Application, but the Application
      // context is available and contains a MortarScope that provides needed
      // services. Thanks, Android!

      //noinspection ResourceType
      scope = context.getApplicationContext().getSystemService(MORTAR_SERVICE);
    }
    return (MortarScope) scope;
  }
422527
public SymbolScope getEnclosingScope(Node n) {
    Node current = n.getParent();
    if (n.isName() && n.getParent().isFunction()) {
      current = current.getParent();
    }

    for (; current != null; current = current.getParent()) {
      if (scopes.containsKey(current)) {
        return scopes.get(current);
      }
    }
    return null;
  }
680320
@NonNull
  public static LocationEngine getBestLocationEngine(@NonNull Context context) {
    checkNotNull(context, "context == null");

    boolean hasGoogleLocationServices = isOnClasspath(GOOGLE_LOCATION_SERVICES);
    if (isOnClasspath(GOOGLE_API_AVAILABILITY)) {
      // Check Google Play services APK is available and up-to-date on this device
      hasGoogleLocationServices &= GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
        == ConnectionResult.SUCCESS;
    }
    return getLocationEngine(context, hasGoogleLocationServices);
  }
979837
public Scope getDefiningScope() {
        Scope enclosing = getEnclosingScope();
        String name = getIdentifier();
        return enclosing == null ? null : enclosing.getDefiningScope(name);
    }
56518
public static WebApplicationService getService(final RequestContext context) {
        return context != null ? (WebApplicationService) context.getFlowScope().get(PARAMETER_SERVICE) : null;
    }
762185
private static Map<String, Object> findScopedMap(final FacesContext facesContext, final Object property)
    {
        if (facesContext == null)
        {
            return null;
        }
        
        final ExternalContext extContext = facesContext.getExternalContext();
        if (extContext == null)
        {
            return null;
        }

        final boolean startup = (extContext instanceof StartupServletExternalContextImpl);
        Map<String, Object> scopedMap;

        // request scope (not available at startup)
        if (!startup)
        {
            scopedMap = extContext.getRequestMap();
            if (scopedMap.containsKey(property))
            {
                return scopedMap;
            }
        }

        // jsf 2.0 view scope
        UIViewRoot root = facesContext.getViewRoot();
        if (root != null)
        {
            scopedMap = root.getViewMap(false);
            if (scopedMap != null && scopedMap.containsKey(property))
            {
                return scopedMap;
            }
        }

        // session scope (not available at startup)
        if (!startup)
        {
            scopedMap = extContext.getSessionMap();
            if (scopedMap.containsKey(property))
            {
                return scopedMap;
            }
        }

        // application scope
        scopedMap = extContext.getApplicationMap();
        if (scopedMap.containsKey(property))
        {
            return scopedMap;
        }

        // not found
        return null;
    }
600743
public static GrailsApplication findApplication(ServletContext servletContext) {
        ApplicationContext wac = findApplicationContext(servletContext);
        if(wac != null) {
            return (GrailsApplication)wac.getBean(GrailsApplication.APPLICATION_ID);
        }
        return null;
    }
921068
@NonNull
    public static BeaconManager getInstanceForApplication(@NonNull Context context) {
        /*
         * Follow double check pattern from Effective Java v2 Item 71.
         *
         * Bloch recommends using the local variable for this for performance reasons:
         *
         * > What this variable does is ensure that `field` is read only once in the common case
         * > where it's already initialized. While not strictly necessary, this may improve
         * > performance and is more elegant by the standards applied to low-level concurrent
         * > programming. On my machine, [this] is about 25 percent faster than the obvious
         * > version without a local variable.
         *
         * Joshua Bloch. Effective Java, Second Edition. Addison-Wesley, 2008. pages 283-284
         */
        BeaconManager instance = sInstance;
        if (instance == null) {
            synchronized (SINGLETON_LOCK) {
                instance = sInstance;
                if (instance == null) {
                    sInstance = instance = new BeaconManager(context);
                }
            }
        }
        return instance;
    }
463108
private Map<String, Object> getScopeMap(Scope scope) {
		switch(scope) {
			case FLASH:
				if(flashAttributesFactoryBean != null) {
					return flashAttributesFactoryBean.getAttributesMap();
				} else {
					return getAttributesMap(flashAttributesFactoryBeanName);
				}
			case REQUEST:
				return getAttributesMap(requestAttributesFactoryBeanName);
			case SESSION:
				return getAttributesMap(sessionAttributesFactoryBeanName);
			case USER:
				return getAttributesMap(userAttributesFactoryBeanName);
			case CLIENTIP:
				return getAttributesMap(clientIPAttributesFactoryBeanName);
			case INSTANCE:
				return getAttributesMap(instanceAttributesFactoryBeanName);
			case GLOBAL:
				return getAttributesMap(globalAttributesFactoryBeanName);
		}
		return null;
	}
1128279
public Scope getEnclosingScope(Scope scope) {
        for (Scope s = this; s != null; s = s.getParent()) {
            if (s.isEnclosing(scope)) {
                return s;
            }
        }
        return null;
    }
911103
public T get() {
        Object object = null;
        try {
            ProxyTarget target = locator.locateProxyTarget();
            if (target != null) {
                try {
                    object = target.getTarget();
                } finally {
                    if (target instanceof ReleasableProxyTarget) {
                        // Sadly we don't know much what is done with the target by the caller, so we just release it
                        // right now
                        ((ReleasableProxyTarget) target).releaseTarget();
                    }
                }
            }
        } catch (RuntimeException e) {
            LOG.trace("locating target failed, will return null then", e);
        }
        return type.cast(object);
    }
314695
function getContext() {
	const ctx = java.lang.Class.forName("android.app.AppGlobals").getMethod("getInitialApplication", null).invoke(null, null);
	if (ctx) { return ctx; }

	return java.lang.Class.forName("android.app.ActivityThread").getMethod("currentApplication", null).invoke(null, null);
}
511415
private int getSearchScope(LdapSearchScope scope) {
        if (scope == LdapSearchScope.ONE_LEVEL) {
            return SearchControls.ONELEVEL_SCOPE;
        } else {
            return SearchControls.SUBTREE_SCOPE;
        }
    }
156130
@Nullable
    private ScopeBlock findScopeBlock(ScopeBlock sb, int pc) {

        if ((pc <= sb.getStart()) || (pc >= sb.getFinish())) {
            return null;
        }

        List<ScopeBlock> children = sb.getChildren();
        if (children != null) {
            for (ScopeBlock child : children) {
                ScopeBlock foundSb = findScopeBlock(child, pc);
                if (foundSb != null) {
                    return foundSb;
                }
            }
        }
        return sb;
    }
784435
@Nullable
    private ScopeBlock findPreviousSiblingScopeBlock(ScopeBlock sb) {
        ScopeBlock parent = sb.getParent();
        if (parent == null) {
            return null;
        }

        List<ScopeBlock> children = parent.getChildren();
        if (children == null) {
            return null;
        }

        ScopeBlock lastSibling = null;
        for (ScopeBlock sibling : children) {
            if (sibling.equals(sb)) {
                return lastSibling;
            }
            lastSibling = sibling;
        }

        return null;
    }
234221
public function chanContext()
    {
        try
        {
            return $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_CONTEXT );
        }
        catch( \Cityware\Snmp\Exception $e )
        {
            return null;
        }
    }
1319133
public Symbol getSymbolForScope(SymbolScope scope) {
    if (scope.getSymbolForScope() == null) {
      scope.setSymbolForScope(findSymbolForScope(scope));
    }
    return scope.getSymbolForScope();
  }