/*
STATIC CONVENIENCE METHODS
426223
private static void replaceAll(StringBuffer s,
			final String o, final String n) {
		int olen = o.length();
		int nlen = n.length();
		int found = s.indexOf(o);
		while (found >= 0) {
			s.replace(found,found + olen,n);
			found = s.indexOf(o,found + nlen);
		}
	}
297964
@Nonnull
  public JSInvocation staticInvoke (@Nullable final AbstractJSClass aType, @Nonnull final JSMethod aMethod)
  {
    final JSInvocation aInvocation = new JSInvocation (aType, aMethod);
    return addStatement (aInvocation);
  }
474345
static <T> Pair<Boolean, T> constructViaMethod(Class<T> type, String fromValue) {

		// Try to usse fromString before valueOf (enums have valueOf already defined) - in case we override fromString()
		List<Method> methods = getMethods(type, "fromString", "valueOf");

		if (methods != null && methods.size() > 0) {

			for (Method method : methods) {

				try {
					Object value = method.invoke(null, fromValue);
					return new Pair(true, value);
				}
				catch (IllegalAccessException | InvocationTargetException e) {
					// failed with this one ... try the others ...
					log.warn("Failed invoking static method: " + method.getName());
				}
			}
		}

		return new Pair<>(false, null);
	}
550562
void outputStaticInjectionMethods(Class<?> type, FragmentMap fragments,
      NameGenerator nameGenerator, SourceWriteUtil sourceWriteUtil) {
    String methodName = nameGenerator.convertToValidMemberName("injectStatic_" + type.getName());
    SourceSnippetBuilder body = new SourceSnippetBuilder();
    for (InjectionPoint injectionPoint : InjectionPoint.forStaticMethodsAndFields(type)) {
      Member member = injectionPoint.getMember();
      try {
        List<InjectorMethod> staticInjectionHelpers = new ArrayList<InjectorMethod>();

        if (member instanceof Method) {
          MethodLiteral<?, Method> method =
              MethodLiteral.get((Method) member, TypeLiteral.get(member.getDeclaringClass()));
          body.append(methodCallUtil.createMethodCallWithInjection(method, null, nameGenerator,
              staticInjectionHelpers));
        } else if (member instanceof Field) {
          FieldLiteral<?> field =
              FieldLiteral.get((Field) member, TypeLiteral.get(member.getDeclaringClass()));
          body.append(sourceWriteUtil.createFieldInjection(field, null, nameGenerator,
              staticInjectionHelpers));
        }

        outputMethods(staticInjectionHelpers, fragments);
      } catch (NoSourceNameException e) {
        errorManager.logError(e.getMessage(), e);
      }
    }

    // Note that the top-level method that performs static injection will only
    // invoke a bunch of other injector methods.  Therefore, it doesn't matter
    // which package it goes in, and we don't need to invoke getUserPackageName
    // (which is good, because in practice users statically inject types that
    // have no user package name because they're private inner classes!)
    String packageName = type.getPackage().getName();
    InjectorMethod method = SourceSnippets.asMethod(false, "private void " + methodName + "()",
        packageName, body.build());
    GinjectorFragmentOutputter fragment =
        fragments.get(fragmentPackageNameFactory.create(packageName));
    fragment.outputMethod(method);
    fragment.invokeInInitializeStaticInjections(methodName);
  }
270581
static String access(ExecutableElement method) {
    Set<Modifier> mods = method.getModifiers();
    if (mods.contains(Modifier.PUBLIC)) {
      return "public ";
    } else if (mods.contains(Modifier.PROTECTED)) {
      return "protected ";
    } else {
      return "";
    }
  }
377730
@Override
    public void visitCode(Code obj) {
        if (!Values.STATIC_INITIALIZER.equals(getMethodName())) {
            state = State.SEEN_NOTHING;
            super.visitCode(obj);
        }
    }
1025225
Expr staticMember() {
		if (peek().sym != Sym.ID) {
			return sharedMethod();
		}
		
		int begin = forward;
		while (move().sym == Sym.DOT && move().sym == Sym.ID) {
			;
		}
		// ID.ID.ID::
		if (peek().sym != Sym.STATIC || tokenList.get(forward - 1).sym != Sym.ID) {
			resetForward(begin);
			return sharedMethod();
		}
		
		String clazz = getClazz(begin);
		match(Sym.STATIC);
		String memberName = match(Sym.ID).value();
		
		// com.jfinal.kit.Str::isBlank(str)
		if (peek().sym == Sym.LPAREN) {
			move();
			if (peek().sym == Sym.RPAREN) {
				move();
				return new StaticMethod(clazz, memberName, location);
			}
			
			ExprList exprList = exprList();
			match(Sym.RPAREN);
			return new StaticMethod(clazz, memberName, exprList, location);
		}
		
		// com.jfinal.core.Const::JFINAL_VERSION
		return new StaticField(clazz, memberName, location);
	}
200658
public static function __static()
	{
		$prefixes = array( STANDARD_PREFIX_SCHEMA, STANDARD_PREFIX_XBRLI, STANDARD_PREFIX_LINK, STANDARD_PREFIX_XLINK, STANDARD_PREFIX_GENERIC, STANDARD_PREFIX_XBRLDT, STANDARD_PREFIX_XBRLDI );
		self::$standardNamespaces = $temp = array_flip( array_intersect_key( self::$standardPrefixes, array_flip( $prefixes ) ) );

		self::$standardArcElements = array_flip(
			array(
				"definitionArc",
				"calculationArc",
				"presentationArc",
				"labelArc",
				"referenceArc",
				"footnoteArc",
			)
		);

		self::$standardLinkElements = array_flip(
			array(
				"definitionLink",
				"calculationLink",
				"presentationLink",
				"labelLink",
				"referenceLink",
				"footnoteLink",
				"label",
				"footnote",
				"reference",
			)
		);

		foreach ( self::$standardArcElements as $arc => $value )
		{
			$qname = self::qnameNS( "link:$arc" );
			self::$standardArcQnames[ (string) $qname ] = $qname;
		}

		foreach ( self::$standardLinkElements as $link => $value )
		{
			/**
			 * @var QName qname
			 */
			$qname = self::qnameNS( "link:$link" );
			self::$standardExtLinkQnamesAndResources[ (string) $qname ] = $qname;
		}

		self::$standardExtLinkQnames = array_filter(
			self::$standardExtLinkQnamesAndResources,
			function( $qname ) { return XBRL::endsWith( $qname->localName, 'Link' ); }
		);

		self::$resourceArcRoles = array_flip(
			array(
				self::$arcRoleConceptLabel,
				self::$arcRoleConceptReference,
				self::$arcRoleFactFootnote,
				self::$genericElementLabel,
				self::$genericElementReference,
			)
		);

		self::$standardLabelRoles = array(
			self::$labelRoleLabel,
			self::$labelRoleTerseLabel,
			self::$labelRoleVerboseLabel,
			self::$labelRolePositiveLabel,
			self::$labelRolePositiveTerseLabel,
			self::$labelRolePositiveVerboseLabel,
			self::$labelRoleNegativeLabel,
			self::$labelRoleNegativeTerseLabel,
			self::$labelRoleNegativeVerboseLabel,
			self::$labelRoleZeroLabel,
			self::$labelRoleZeroTerseLabel,
			self::$labelRoleZeroVerboseLabel,
			self::$labelRoleTotalLabel,
			self::$labelRolePeriodStartLabel,
			self::$labelRolePeriodEndLabel,
			self::$labelRoleDocumentation,
			self::$labelRoleDefinitionGuidance,
			self::$labelRoleDisclosureGuidance,
			self::$labelRolePresentationGuidance,
			self::$labelRoleMeasurementGuidance,
			self::$labelRoleCommentaryGuidance,
			self::$labelRoleExampleGuidance,
		);

		self::$standardRoles = array_flip(
			array_merge(
				self::$standardLabelRoles,
				self::$standardReferenceRoles,
				self::$standardLinkbaseRefRoles,
				array(
						self::$defaultLinkRole,
						self::$footnote,
				)
			)
		);

		self::$standardArcRoles = array_flip(
			array(
				self::$linkCalculationArc,
				self::$linkDefinitionArc,
				self::$linkFootnoteArc,
				self::$linkLabelArc,
				self::$linkPresentationArc,
				self::$linkReferenceArc,
			)
		);

		self::$standardArcroleCyclesAllowed = array(
			self::$arcRoleConceptLabel		=> array( "any", null ),
			self::$arcRoleConceptReference	=> array( "any", null ),
			self::$arcRoleFactFootnote		=> array( "any", null ),
			self::$arcRoleParentChild		=> array( "undirected", "xbrl.5.2.4.2" ),
			self::$arcRoleSummationItem		=> array( "any", "xbrl.5.2.5.2" ),
			self::$arcRoleGeneralSpecial	=> array( "undirected", "xbrl.5.2.6.2.1" ),
			self::$arcRoleEssenceAlias		=> array( "undirected", "xbrl.5.2.6.2.1" ),
			self::$arcRoleSimilarTuples		=> array( "any", "xbrl.5.2.6.2.3" ),
			self::$arcRoleRequiresElement	=> array( "any", "xbrl.5.2.6.2.4" ),
		);

		self::$consecutiveArcrole = array( // can be list of or single arcrole
			'all'						=> array( self::$arcRoleDimensionDomain, self::$arcRoleHypercubeDimension ),
			'notAll'					=> array( self::$arcRoleDimensionDomain, self::$arcRoleHypercubeDimension ),
			'hypercubeDimension'		=> self::$arcRoleDimensionDomain,
			'dimensionDomain'			=> array( self::$arcRoleDomainMember, self::$arcRoleAll, self::$arcRoleNotAll ),
			'domainMember'				=> array( self::$arcRoleDomainMember, self::$arcRoleAll, self::$arcRoleNotAll ),
			'dimensionDefault'			=> array(),
		);

		self::$hasHypercube = array(
			self::$arcRoleAll,
			self::$arcRoleNotAll,
		);

		self::$standardLinkbaseRefRoles = array(
			self::$CalculationLinkbaseRef,
			self::$DefinitionLinkbaseRef,
			self::$LabelLinkbaseRef,
			self::$PresentationLinkbaseRef,
			self::$ReferenceLinkbaseRef,
		);

		self::$arcCustomAttributesExclusions = array(
			'http://www.w3.org/2000/xmlns',
			self::$standardPrefixes[ STANDARD_PREFIX_XLINK ],
			"use",
			"priority",
			"order",
		);

		self::$xbrliSubstitutionHeads = array(
			self::$xbrldtDimensionItem,
			self::$xbrldtHypercubeItem,
			self::$xbrliItem,
			self::$xbrliTuple,
		);

		self::$arcRoleDimensional = array(
			XBRL_Constants::$arcRoleAll,
			XBRL_Constants::$arcRoleNotAll,
			XBRL_Constants::$arcRoleDimensionDomain,
			XBRL_Constants::$arcRoleDomainMember,
			XBRL_Constants::$arcRoleDimensionMember,
			XBRL_Constants::$arcRoleHypercubeDimension,
			XBRL_Constants::$arcRoleDimensionDefault,
		);
	}
829311
@VisibleForTesting
    static Method getMethod(Class<?> cls, String name, Class<?>... params) {
        Method m;
        try {
            m = cls.getDeclaredMethod(name, params);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        m.setAccessible(true);
        return m;
    }
341603
static <T extends Enum<T>>
    T get( Class<T> clazz, int v ) {
        return get(clazz).constant(v);
    }
431166
public static function __static()
	{
		SequenceTypes::$Void = SequenceType::WithTypeCode( XmlTypeCode::None );
		SequenceTypes::$Item = SequenceType::WithTypeCode( XmlTypeCode::Item );
		SequenceTypes::$ItemS = SequenceType::WithTypeCodeAndCardinality( XmlTypeCode::Item, XmlTypeCardinality::ZeroOrMore );
		SequenceTypes::$Node = SequenceType::WithTypeCode( XmlTypeCode::Node );
		SequenceTypes::$ProcessingInstruction = SequenceType::WithTypeCode( XmlTypeCode::ProcessingInstruction );
		SequenceTypes::$Text = SequenceType::WithTypeCode( XmlTypeCode::Text );
		SequenceTypes::$Comment = SequenceType::WithTypeCode( XmlTypeCode::Comment );
		SequenceTypes::$Element = SequenceType::WithTypeCode( XmlTypeCode::Element );
		SequenceTypes::$Attribute = SequenceType::WithTypeCode( XmlTypeCode::Attribute );
		SequenceTypes::$Document = SequenceType::WithTypeCode( XmlTypeCode::Document );
		SequenceTypes::$Boolean = SequenceType::WithTypeCode( XmlTypeCode::Boolean );
		SequenceTypes::$AnyAtomicType = SequenceType::WithTypeCode( XmlTypeCode::AnyAtomicType );
		SequenceTypes::$AnyAtomicTypeO = SequenceType::WithTypeCodeAndCardinality( XmlTypeCode::AnyAtomicType, XmlTypeCardinality::ZeroOrOne );
		SequenceTypes::$Double = SequenceType::WithTypeCode( XmlTypeCode::Double );
		SequenceTypes::$Float = SequenceType::WithTypeCode( XmlTypeCode::Float );
		SequenceTypes::$Date = SequenceType::WithTypeCode( XmlTypeCode::Date );
		SequenceTypes::$Time = SequenceType::WithTypeCode( XmlTypeCode::Time );
		SequenceTypes::$DateTime = SequenceType::WithTypeCode( XmlTypeCode::DateTime );
		SequenceTypes::$StringX = SequenceType::WithTypeCodeAndCardinality (XmlTypeCode::String, XmlTypeCardinality::ZeroOrOne );
		SequenceTypes::$Int = SequenceType::WithTypeCode( XmlTypeCode::Int );
		SequenceTypes::$AnyUri = SequenceType::WithTypeCode( XmlTypeCode::AnyUri );
	}
121969
function doBindStatic(func) {
        /*jshint validthis:true*/
        var args = toArray(arguments),
            bound;

        if (this && !func[$wrapped] && this.$static && this.$static[$class]) {
            func = wrapMethod(null, func, this.$self || this.$static, true);
        }

        args.splice(1, 0, this);
        bound = bind.apply(func, args);

        return bound;
    }
271868
private void checkFactoryMethodArguments(int arguments) {
        for (Method m : typeDef.getMethods()) {
            int a = m.getArguments() != null ? m.getArguments().size() : 0;
            if (m.getName().equals(staticFactoryMethod) && a == arguments && m.isStatic()) {
                return;
            }
        }
        throw new IllegalArgumentException("No static method found on " + typeDef.getName() + " with name " + staticFactoryMethod + " and " + arguments + " arguments.");
    }
1193705
public static void initStaticDefaultParameterValues(QueryParameter param,
                                                  Map<String, Object> parameterValues) throws QueryException {
        List<Serializable> defValues;
        if ((param.getDefaultValues() != null) && (param.getDefaultValues().size() > 0)) {
            defValues = param.getDefaultValues();
        } else {
			throw new QueryException(
					"Invalid use of method initStaticDefaultParameterValues : no static values for parameter "
							+ param.getName());
        }
        initDefaultParameterValues(param, defValues, parameterValues);
    }
885596
private Object getStaticMethods(Class sender, String name) {
        final MetaMethodIndex.Entry entry = metaMethodIndex.getMethods(sender, name);
        if (entry == null)
            return FastArray.EMPTY_LIST;
        Object answer = entry.staticMethods;
        if (answer == null)
            return FastArray.EMPTY_LIST;
        return answer;
    }
593034
@Override
    public void visitCode(Code obj) {
        stack.resetForMethodEntry(this);
        exemptExecutors.clear();

        if (!hangingFieldCandidates.isEmpty()) {
            isInitializer = (Values.STATIC_INITIALIZER.equals(methodName) || Values.CONSTRUCTOR.equals(methodName));
            super.visitCode(obj);
        }
    }
302473
static function &getInstance($key=null)
	{
		static $instances;

		if (!isset($instances))
		{
			$instances = array();
		}

		if (!isset($instances[$key]))
		{
			$instances[$key] = new static($key);
		}

		return $instances[$key];
	}