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


Java Modifier.isAbstract方法代碼示例

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


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

示例1: endVisit

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
@Override
public void endVisit(MethodDeclaration node) {
  if (Modifier.isAbstract(node.getModifiers())) {
    if (!TranslationUtil.needsReflection(node.getMethodBinding().getDeclaringClass())) {
      unit.setHasIncompleteProtocol();
      unit.setHasIncompleteImplementation();
      return;
    }
    Block body = new Block();
    // Generate a body which throws a NSInvalidArgumentException.
    String bodyCode = "// can't call an abstract method\n"
        + "[self doesNotRecognizeSelector:_cmd];";
    if (!Types.isVoidType(node.getReturnType().getTypeBinding())) {
      bodyCode += "\nreturn 0;"; // Never executes, but avoids a gcc warning.
    }
    body.getStatements().add(new NativeStatement(bodyCode));
    node.setBody(body);
    node.removeModifiers(Modifier.ABSTRACT);
  }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:21,代碼來源:AbstractMethodRewriter.java

示例2: visitType

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
private void visitType(AbstractTypeDeclaration node) {
  ITypeBinding typeBinding = node.getTypeBinding();
  if (!Modifier.isAbstract(node.getModifiers()) && !typeBinding.isEnum()) {
    return;
  }
  // Find any interface methods that aren't defined by this abstract type so
  // we can silence incomplete protocol errors.
  // Collect needed methods from this interface and all super-interfaces.
  Queue<ITypeBinding> interfaceQueue = new LinkedList<ITypeBinding>();
  Set<IMethodBinding> interfaceMethods = new LinkedHashSet<IMethodBinding>();
  interfaceQueue.addAll(Arrays.asList(typeBinding.getInterfaces()));
  ITypeBinding intrface;
  while ((intrface = interfaceQueue.poll()) != null) {
    interfaceMethods.addAll(Arrays.asList(intrface.getDeclaredMethods()));
    interfaceQueue.addAll(Arrays.asList(intrface.getInterfaces()));
  }

  // Check if any interface methods are missing from the implementation
  for (IMethodBinding interfaceMethod : interfaceMethods) {
    if (!isMethodImplemented(typeBinding, interfaceMethod)) {
      unit.setHasIncompleteProtocol();
    }
  }
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:25,代碼來源:AbstractMethodRewriter.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: printMethodDeclaration

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
@Override
protected void printMethodDeclaration(MethodDeclaration m) {
  if (typeBinding.isInterface() || Modifier.isAbstract(m.getModifiers())) {
    return;
  }
  newline();
  syncLineNumbers(m.getName());  // avoid doc-comment
  String methodBody = generateStatement(m.getBody(), /* isFunction */ false);
  print(getMethodSignature(m) + " " + reindent(methodBody) + "\n");
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:11,代碼來源:TypeImplementationGenerator.java

示例6: canFunctionize

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
/**
 * Determines whether an instance method can be functionized.
 */
private boolean canFunctionize(MethodDeclaration node) {
  IMethodBinding m = node.getMethodBinding();
  int modifiers = node.getModifiers();

  // Never functionize these types of methods.
  if (Modifier.isStatic(modifiers) || Modifier.isAbstract(modifiers)
      || BindingUtil.isSynthetic(modifiers) || m.isAnnotationMember()
      || BindingUtil.isDestructor(m)) {
    return false;
  }

  // Don't functionize equals/hash, since they are often called by collections.
  String name = m.getName();
  if ((name.equals("hashCode") && m.getParameterTypes().length == 0)
      || (name.equals("equals") && m.getParameterTypes().length == 1)) {
    return false;
  }

  if (!BindingUtil.isPrivate(m) && !BindingUtil.isFinal(m)) {
    return false;
  }

  // Don't functionzie a mapped method
  if (BindingUtil.isMappedToNative(node.getMethodBinding())) {
    return false;
  }

  return !hasSuperMethodInvocation(node);
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:33,代碼來源:Functionizer.java

示例7: isDefaultMethod

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
public static boolean isDefaultMethod(IMethodBinding method) {
  int modifiers = method.getModifiers();
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=405517#c7
  ITypeBinding declaringClass = method.getDeclaringClass();
  if (declaringClass.isInterface()) {
    return !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers);
  }
  return false;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:10,代碼來源:JdtFlags.java

示例8: needsExplicitCast

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
/**
 * @param status the status
 * @return <code>true</code> if explicit cast is needed otherwise <code>false</code>
 */
private boolean needsExplicitCast(RefactoringStatus status) {
  // if the return type of the method is the same as the type of the
  // returned expression then we don't need an explicit cast.
  if (fSourceProvider.returnTypeMatchesReturnExpressions()) return false;

  List<Expression> returnExprs = fSourceProvider.getReturnExpressions();
  // it is inferred that only methods consisting of a single
  // return statement can be inlined as parameters in other
  // method invocations
  if (returnExprs.size() != 1) return false;

  if (fTargetNode.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) {
    MethodInvocation methodInvocation = (MethodInvocation) fTargetNode.getParent();
    if (methodInvocation.getExpression() == fTargetNode) return false;
    IMethodBinding method = methodInvocation.resolveMethodBinding();
    if (method == null) {
      status.addError(
          RefactoringCoreMessages.CallInliner_cast_analysis_error,
          JavaStatusContext.create(fCUnit, methodInvocation));
      return false;
    }
    ITypeBinding[] parameters = method.getParameterTypes();
    int argumentIndex = methodInvocation.arguments().indexOf(fInvocation);

    ITypeBinding parameterType = returnExprs.get(0).resolveTypeBinding();
    if (method.isVarargs() && argumentIndex >= parameters.length - 1) {
      argumentIndex = parameters.length - 1;
      parameterType = parameterType.createArrayType(1);
    }
    parameters[argumentIndex] = parameterType;

    ITypeBinding type = ASTNodes.getReceiverTypeBinding(methodInvocation);
    TypeBindingVisitor visitor =
        new AmbiguousMethodAnalyzer(
            fTypeEnvironment, method, fTypeEnvironment.create(parameters));
    if (!visitor.visit(type)) {
      return true;
    } else if (type.isInterface()) {
      return !Bindings.visitInterfaces(type, visitor);
    } else if (Modifier.isAbstract(type.getModifiers())) {
      return !Bindings.visitHierarchy(type, visitor);
    } else {
      // it is not needed to visit interfaces if receiver is a concrete class
      return !Bindings.visitSuperclasses(type, visitor);
    }
  } else {
    ITypeBinding explicitCast =
        ASTNodes.getExplicitCast(returnExprs.get(0), (Expression) fTargetNode);
    return explicitCast != null;
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:56,代碼來源:CallInliner.java

示例9: checkFinalConditions

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
  try {
    pm.beginTask(RefactoringCoreMessages.IntroduceFactory_checking_preconditions, 1);
    RefactoringStatus result = new RefactoringStatus();

    if (fFactoryClassName != null) result.merge(setFactoryClass(fFactoryClassName));
    if (result.hasFatalError()) return result;
    fArgTypes = fCtorBinding.getParameterTypes();
    fCtorIsVarArgs = fCtorBinding.isVarargs();
    fAllCallsTo = findAllCallsTo(fCtorBinding, pm, result);
    fFormalArgNames = findCtorArgNames();

    ICompilationUnit[] affectedFiles = collectAffectedUnits(fAllCallsTo);
    result.merge(
        Checks.validateModifiesFiles(
            ResourceUtil.getFiles(affectedFiles), getValidationContext()));

    if (fCallSitesInBinaryUnits)
      result.merge(
          RefactoringStatus.createWarningStatus(
              RefactoringCoreMessages.IntroduceFactory_callSitesInBinaryClass));

    if (Modifier.isAbstract(fCtorBinding.getDeclaringClass().getModifiers())) {
      result.merge(
          RefactoringStatus.createWarningStatus(
              RefactoringCoreMessages.IntroduceFactory_abstractClass));
    }

    return result;
  } finally {
    pm.done();
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:35,代碼來源:IntroduceFactoryRefactoring.java

示例10: isAbstract

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
public static boolean isAbstract(TypeDeclaration typeDeclaration) {
	for (Object elem : typeDeclaration.modifiers()) {
		IExtendedModifier extendedModifier = (IExtendedModifier) elem;
		if (extendedModifier.isModifier()) {
			Modifier modifier = (Modifier) extendedModifier;
			if (modifier.isAbstract()) {
				return true;
			}
		}
	}
	return false;
}
 
開發者ID:ELTE-Soft,項目名稱:txtUML,代碼行數:13,代碼來源:ElementTypeTeller.java

示例11: 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

示例12: isAbstract

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
private static boolean isAbstract(TypeDeclaration decl) {
    int modifiers = decl.getModifiers();
    return (Modifier.isAbstract(modifiers));
}
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:5,代碼來源:JavaASTVisitor.java

示例13: findUnimplementedInterfaceMethods

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
private static void findUnimplementedInterfaceMethods(ITypeBinding typeBinding, HashSet<ITypeBinding> visited,
		ArrayList<IMethodBinding> allMethods, IPackageBinding currPack, ArrayList<IMethodBinding> toImplement) {

	if (visited.add(typeBinding)) {
		IMethodBinding[] typeMethods= typeBinding.getDeclaredMethods();

		nextMethod: for (int i= 0; i < typeMethods.length; i++) {
			IMethodBinding curr= typeMethods[i];
			for (Iterator<IMethodBinding> allIter= allMethods.iterator(); allIter.hasNext();) {
				IMethodBinding oneMethod= allIter.next();
				if (Bindings.isSubsignature(oneMethod, curr)) {
					// We've already seen a method that is a subsignature of curr.
					if (!Bindings.isSubsignature(curr, oneMethod)) {
						// oneMethod is a true subsignature of curr; let's go with oneMethod
						continue nextMethod;
					}
					// Subsignatures are equivalent.
					// Check visibility and return types ('getErasure()' tries to achieve effect of "rename type variables")
					if (Bindings.isVisibleInHierarchy(oneMethod, currPack)
							&& oneMethod.getReturnType().getErasure().isSubTypeCompatible(curr.getReturnType().getErasure())) {
						// oneMethod is visible and curr doesn't have a stricter return type; let's go with oneMethod
						continue nextMethod;
					}
					// curr is stricter than oneMethod, so let's remove oneMethod
					allIter.remove();
					toImplement.remove(oneMethod);
				} else if (Bindings.isSubsignature(curr, oneMethod)) {
					// curr is a true subsignature of oneMethod. Let's remove oneMethod.
					allIter.remove();
					toImplement.remove(oneMethod);
				}
			}
			int modifiers= curr.getModifiers();
			if (!Modifier.isStatic(modifiers)) {
				allMethods.add(curr);
				if (Modifier.isAbstract(modifiers)) {
					toImplement.add(curr);
				}
			}
		}
		ITypeBinding[] superInterfaces= typeBinding.getInterfaces();
		for (int i= 0; i < superInterfaces.length; i++) {
			findUnimplementedInterfaceMethods(superInterfaces[i], visited, allMethods, currPack, toImplement);
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:47,代碼來源:StubUtility2.java

示例14: getStub

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
private MethodDeclaration getStub(ASTRewrite rewrite, ASTNode targetTypeDecl) throws CoreException {
	ImportRewriteContext context=new ContextSensitiveImportRewriteContext(targetTypeDecl, getImportRewrite());

	AST ast= targetTypeDecl.getAST();
	MethodDeclaration decl= ast.newMethodDeclaration();

	SimpleName newNameNode= getNewName(rewrite);

	decl.setConstructor(isConstructor());

	addNewModifiers(rewrite, targetTypeDecl, decl.modifiers());

	ArrayList<String> takenNames= new ArrayList<>();
	addNewTypeParameters(rewrite, takenNames, decl.typeParameters(), context);

	decl.setName(newNameNode);

	IVariableBinding[] declaredFields= fSenderBinding.getDeclaredFields();
	for (int i= 0; i < declaredFields.length; i++) { // avoid to take parameter names that are equal to field names
		takenNames.add(declaredFields[i].getName());
	}

	String bodyStatement= ""; //$NON-NLS-1$
	boolean isAbstractMethod= Modifier.isAbstract(decl.getModifiers()) || (fSenderBinding.isInterface() && !Modifier.isStatic(decl.getModifiers()) && !Modifier.isDefault(decl.getModifiers()));
	if (!isConstructor()) {
		Type returnType= getNewMethodType(rewrite, context);
		decl.setReturnType2(returnType);

		boolean isVoid= returnType instanceof PrimitiveType && PrimitiveType.VOID.equals(((PrimitiveType)returnType).getPrimitiveTypeCode());
		if (!isAbstractMethod && !isVoid) {
			ReturnStatement returnStatement= ast.newReturnStatement();
			returnStatement.setExpression(ASTNodeFactory.newDefaultExpression(ast, returnType, 0));
			bodyStatement= ASTNodes.asFormattedString(returnStatement, 0, String.valueOf('\n'), getCompilationUnit().getJavaProject().getOptions(true));
		}
	}

	addNewParameters(rewrite, takenNames, decl.parameters(), context);
	addNewExceptions(rewrite, decl.thrownExceptionTypes(), context);

	Block body= null;
	if (!isAbstractMethod && !Flags.isAbstract(decl.getModifiers())) {
		body= ast.newBlock();
		if (bodyStatement.length() > 0) {
			ReturnStatement todoNode = (ReturnStatement) rewrite.createStringPlaceholder(bodyStatement,
					ASTNode.RETURN_STATEMENT);
			body.statements().add(todoNode);
		}
	}
	decl.setBody(body);

	CodeGenerationSettings settings = PreferenceManager.getCodeGenerationSettings(getCompilationUnit().getResource());
	if (settings.createComments && !fSenderBinding.isAnonymous()) {
		String string = CodeGeneration.getMethodComment(getCompilationUnit(), fSenderBinding.getName(), decl, null,
				String.valueOf('\n'));
		if (string != null) {
			Javadoc javadoc= (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
			decl.setJavadoc(javadoc);
		}
	}
	return decl;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:62,代碼來源:AbstractMethodCorrectionProposal.java

示例15: compute

import org.eclipse.jdt.core.dom.Modifier; //導入方法依賴的package包/類
public void compute(Set<IObject> allObjects) {
	// store this
	this.allObjects = allObjects;
	this.objectInfos = new HashSet<ObjectInfo>(); 
	
	Crystal crystal = Crystal.getInstance();
	
	for (IObject object : allObjects) {
		Type objectType = object.getC();
		
		String typeName = objectType.getFullyQualifiedName();
		
		Set<String> allSuperClasses = new HashSet<String>();
		
		// TODO: Include transitive supertypes, starting from the current one
		// TODO: Exclude maybe abstract classes and interfaces, things that cannot be instantiated?
		// NOTE: Here, we include interfaces.
		
		if (includeSuperClasses) {
			Util.getSuperClasses(objectType, allSuperClasses, includeInterfaces);
		}
		else {
			allSuperClasses.add(typeName);
		}
		
		for (String type : allSuperClasses) {
			ObjectTypeInfo typeInfo = new ObjectTypeInfo();
			
			ITypeBinding typeBinding = crystal.getTypeBindingFromName(type);
			if (typeBinding != null ) {
				typeInfo.isAbstract = Modifier.isAbstract(typeBinding.getModifiers());
				typeInfo.isInterface = typeBinding.isInterface();
			}

			typeInfo.type = type;
			// Update calculated fields
			typeInfo.calculate();
			this.objectInfos.add(typeInfo);
		}
	}
}
 
開發者ID:aroog,項目名稱:code,代碼行數:42,代碼來源:AllObjectTypes.java


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