當前位置: 首頁>>代碼示例>>Java>>正文


Java Modifier.isNative方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.Modifier.isNative方法的典型用法代碼示例。如果您正苦於以下問題:Java Modifier.isNative方法的具體用法?Java Modifier.isNative怎麽用?Java Modifier.isNative使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.Modifier的用法示例。


在下文中一共展示了Modifier.isNative方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: endVisit

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
@Override
public void endVisit(MethodDeclaration node) {
  int modifiers = node.getModifiers();
  if (Modifier.isNative(modifiers)) {
    String nativeCode = extractNativeCode(node);
    if (nativeCode != null) {
      Block body = new Block();
      body.getStatements().add(new NativeStatement(nativeCode));
      node.setBody(body);
      node.removeModifiers(Modifier.NATIVE);
    }
  }
  if (Modifier.isSynchronized(modifiers)) {
    ITypeBinding declaringClass = node.getMethodBinding().getDeclaringClass();
    SynchronizedStatement syncStmt = new SynchronizedStatement(
        Modifier.isStatic(modifiers) ? new TypeLiteral(declaringClass)
        : new ThisExpression(declaringClass));
    syncStmt.setBody(TreeUtil.remove(node.getBody()));
    Block newBody = new Block();
    newBody.getStatements().add(syncStmt);
    node.setBody(newBody);
    node.removeModifiers(Modifier.SYNCHRONIZED);
  }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:25,代碼來源:OcniExtractor.java

示例2: removeDeadMethods

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
/**
 * Remove dead methods from a type's body declarations.
 */
private void removeDeadMethods(String clazz, List<BodyDeclaration> declarations) {
  Iterator<BodyDeclaration> declarationsIter = declarations.iterator();
  while (declarationsIter.hasNext()) {
    BodyDeclaration declaration = declarationsIter.next();
    if (declaration instanceof MethodDeclaration) {
      MethodDeclaration method = (MethodDeclaration) declaration;
      // Need to keep native methods because otherwise the OCNI content will
      // be emitted without a surrounding method.
      // TODO(kstanger): Remove the method and its OCNI comment.
      if (Modifier.isNative(method.getModifiers())) {
        continue;
      }
      IMethodBinding binding = method.getMethodBinding();
      String name = getProGuardName(binding);
      String signature = BindingUtil.getSignature(binding);
      if (deadCodeMap.isDeadMethod(clazz, name, signature)) {
        declarationsIter.remove();
      }
    }
  }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:25,代碼來源:DeadCodeEliminator.java

示例3: getAdornmentFlags

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
private static int getAdornmentFlags(IBinding binding) {
  int adornments = 0;
  final int modifiers = binding.getModifiers();
  if (Modifier.isAbstract(modifiers)) adornments |= JavaElementImageDescriptor.ABSTRACT;
  if (Modifier.isFinal(modifiers)) adornments |= JavaElementImageDescriptor.FINAL;
  if (Modifier.isStatic(modifiers)) adornments |= JavaElementImageDescriptor.STATIC;

  if (binding.isDeprecated()) adornments |= JavaElementImageDescriptor.DEPRECATED;

  if (binding instanceof IMethodBinding) {
    if (((IMethodBinding) binding).isConstructor())
      adornments |= JavaElementImageDescriptor.CONSTRUCTOR;
    if (Modifier.isSynchronized(modifiers)) adornments |= JavaElementImageDescriptor.SYNCHRONIZED;
    if (Modifier.isNative(modifiers)) adornments |= JavaElementImageDescriptor.NATIVE;
    ITypeBinding type = ((IMethodBinding) binding).getDeclaringClass();
    if (type.isInterface() && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers))
      adornments |= JavaElementImageDescriptor.DEFAULT_METHOD;
    if (((IMethodBinding) binding).getDefaultValue() != null)
      adornments |= JavaElementImageDescriptor.ANNOTATION_DEFAULT;
  }
  if (binding instanceof IVariableBinding && ((IVariableBinding) binding).isField()) {
    if (Modifier.isTransient(modifiers)) adornments |= JavaElementImageDescriptor.TRANSIENT;
    if (Modifier.isVolatile(modifiers)) adornments |= JavaElementImageDescriptor.VOLATILE;
  }
  return adornments;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:27,代碼來源:BindingLabelProvider.java

示例4: printModifiers

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
private void printModifiers(int modifiers) {
  if (Modifier.isPublic(modifiers)) {
    sb.print("public ");
  }
  if (Modifier.isProtected(modifiers)) {
    sb.print("protected ");
  }
  if (Modifier.isPrivate(modifiers)) {
    sb.print("private ");
  }
  if (Modifier.isStatic(modifiers)) {
    sb.print("static ");
  }
  if (Modifier.isAbstract(modifiers)) {
    sb.print("abstract ");
  }
  if (Modifier.isFinal(modifiers)) {
    sb.print("final ");
  }
  if (Modifier.isSynchronized(modifiers)) {
    sb.print("synchronized ");
  }
  if (Modifier.isVolatile(modifiers)) {
    sb.print("volatile ");
  }
  if (Modifier.isNative(modifiers)) {
    sb.print("native ");
  }
  if (Modifier.isStrictfp(modifiers)) {
    sb.print("strictfp ");
  }
  if (Modifier.isTransient(modifiers)) {
    sb.print("transient ");
  }
  if ((modifiers & BindingUtil.ACC_SYNTHETIC) > 0) {
    sb.print("synthetic ");
  }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:39,代碼來源:DebugASTPrinter.java

示例5: printFunctionDeclaration

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
@Override
protected void printFunctionDeclaration(FunctionDeclaration function) {
  newline();
  // We expect native functions to be defined externally.
  if (!Modifier.isNative(function.getModifiers())) {
    print("__attribute__((unused)) static ");
  }
  print(getFunctionSignature(function));
  if (function.returnsRetained()) {
    print(" NS_RETURNS_RETAINED");
  }
  println(";");
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:14,代碼來源:TypePrivateDeclarationGenerator.java

示例6: printFunctionDeclaration

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
@Override
protected void printFunctionDeclaration(FunctionDeclaration function) {
  if (Modifier.isNative(function.getModifiers())) {
    return;
  }
  String functionBody = generateStatement(function.getBody(), /* isFunction */ true);
  newline();
  println(getFunctionSignature(function) + " " + reindent(functionBody));
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:10,代碼來源:TypeImplementationGenerator.java

示例7: endVisit

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
@Override
public void endVisit(MethodDeclaration method) {
  if (Modifier.isNative(method.getModifiers())) {
    JavaValidationResult methodResult = JsniParser.parse(method);

    // Collect all Java references we found in this method
    result.addAllJavaRefs(methodResult.getJavaRefs());

    // Report problems, unless we're suppressing them
    if (!JavaASTUtils.hasSuppressWarnings(method, "jsni")) {
      result.addAllProblems(methodResult.getProblems());
    }
  }
}
 
開發者ID:gwt-plugins,項目名稱:gwt-eclipse-plugin,代碼行數:15,代碼來源:JavaValidationVisitor.java

示例8: extractBasicModifiersFromBinding

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
private void extractBasicModifiersFromBinding(int modifiers, NamedEntity entity) {
	Boolean publicModifier = Modifier.isPublic(modifiers);
	Boolean protectedModifier = Modifier.isProtected(modifiers);
	Boolean privateModifier = Modifier.isPrivate(modifiers);
	if (publicModifier )
		entity.addModifiers("public");
	if (protectedModifier)
		entity.addModifiers("protected");
	if (privateModifier)
		entity.addModifiers("private");
	if (!(publicModifier || protectedModifier || privateModifier))
		entity.addModifiers("package");
	if (Modifier.isFinal(modifiers))
		entity.addModifiers("final");
	if (Modifier.isAbstract(modifiers))
		entity.addModifiers("abstract");
	if (Modifier.isNative(modifiers))
		entity.addModifiers("native");
	if (Modifier.isSynchronized(modifiers))
		entity.addModifiers("synchronized");
	if (Modifier.isTransient(modifiers))
		entity.addModifiers("transient");
	if (Modifier.isVolatile(modifiers))
		entity.addModifiers("volatile");
	/*	We do not extract the static modifier here because we want to set the hasClassScope property
		and we do that specifically only for attributes and methods */  
}
 
開發者ID:feenkcom,項目名稱:jdt2famix,代碼行數:28,代碼來源:InJavaImporter.java

示例9: endVisit

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
@Override
public void endVisit(MethodDeclaration node) {
  IMethodBinding binding = node.getMethodBinding();

  if (BindingUtil.isMappedToNative(binding)
      || isConstructorOfMappedClass(binding)) {
    // mapped method should not be functionized. they will not
    //   be called anyways
    if (binding.isConstructor()) {
      node.getBody()
          .getStatements()
          .add(new ReturnStatement(new ThisExpression(binding.getDeclaringClass())));
    }
    return;
  }

  FunctionDeclaration function = null;
  List<BodyDeclaration> declarationList = TreeUtil.asDeclarationSublist(node);
  List<String> extraSelectors = NameTable.getExtraSelectors(binding);
  if (BindingUtil.isStatic(binding) || binding.isConstructor()
      || Modifier.isNative(node.getModifiers()) || functionizableMethods.contains(binding)
      || !extraSelectors.isEmpty()) {
    ITypeBinding declaringClass = binding.getDeclaringClass();
    function = makeFunction(node);

    for (String selector : extraSelectors) {
      declarationList.add(makeExtraMethodDeclaration(node, selector, function));
    }
    declarationList.add(function);
    if (binding.isConstructor() && !BindingUtil.isAbstract(declaringClass)) {
      declarationList.add(makeAllocatingConstructor(node));
    }
    boolean keepMethod = !BindingUtil.isStatic(binding) || !Options.removeClassMethods();
    if (keepMethod || TranslationUtil.needsReflection(declaringClass)) {
      setFunctionCaller(node, function);
      if (!keepMethod) {
        // We're only keeping the method for reflection, so we can keep it out
        // of the declaration.
        node.addModifiers(BindingUtil.ACC_SYNTHETIC);
      }
      if (binding.isConstructor()) {
        node.getBody()
            .getStatements()
            .add(new ReturnStatement(new ThisExpression(binding.getDeclaringClass())));
      }
    } else {
      node.remove();
    }

    ErrorUtil.functionizedMethod();
  }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:53,代碼來源:Functionizer.java

示例10: makeFunction

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
/**
 * Create an equivalent function declaration for a given method.
 */
private FunctionDeclaration makeFunction(MethodDeclaration method) {
  IMethodBinding m = method.getMethodBinding();
  ITypeBinding declaringClass = m.getDeclaringClass();
  boolean isInstanceMethod = !BindingUtil.isStatic(m) && !m.isConstructor();

  FunctionDeclaration function = new FunctionDeclaration(
      NameTable.getFullFunctionName(m), m.getReturnType());

  if (!BindingUtil.isStatic(m)) {
    GeneratedVariableBinding var = new GeneratedVariableBinding(NameTable.SELF_NAME, 0,
        declaringClass, false, true, declaringClass, null);
    function.getParameters().add(new SingleVariableDeclaration(var));
  }
  TreeUtil.copyList(method.getParameters(), function.getParameters());
  function.setModifiers(
      BindingUtil.isPrivate(m) || isInstanceMethod ? Modifier.PRIVATE : Modifier.PUBLIC);

  if (Modifier.isNative(method.getModifiers())) {
    function.addModifiers(Modifier.NATIVE);
    return function;
  }

  function.setBody(TreeUtil.remove(method.getBody()));

  if (BindingUtil.isStatic(m)) {
    // Add class initialization invocation, since this may be the first use of this class.
    if (!BindingUtil.isMappedToNative(declaringClass)) {
      // Note, if the class is mapped to a native class, such initialization is not needed
      String initName = String.format("%s_initialize", NameTable.getFullName(declaringClass));
      ITypeBinding voidType = Types.resolveJavaType("void");
      FunctionInvocation initCall =
          new FunctionInvocation(initName, voidType, voidType, declaringClass);
      function.getBody().getStatements().add(0, new ExpressionStatement(initCall));
    }
  }

  if (!BindingUtil.isStatic(m)) {
    FunctionConverter.convert(function);
  }

  return function;
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:46,代碼來源:Functionizer.java

示例11: isNative

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
public static boolean isNative(IBinding binding) {
  return Modifier.isNative(binding.getModifiers());
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:4,代碼來源:BindingUtil.java


注:本文中的org.eclipse.jdt.core.dom.Modifier.isNative方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。