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


Java Modifier類代碼示例

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


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

示例1: visit

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
    Type fieldType = fieldDeclaration.getType();
    int fieldModifiers = fieldDeclaration.getModifiers();
    Visibility visibility = getVisibility(fieldModifiers);
    // boolean isFinal = (fieldModifiers & Modifier.FINAL) != 0;
    boolean isStatic = (fieldModifiers & Modifier.STATIC) != 0;
    List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
    for (VariableDeclarationFragment fragment : fragments) {
        String fieldName = fragment.getName().getIdentifier();
        final SDAttribute attribute = model.createAttribute(fieldName, containerStack.peek());
        attribute.setStatic(isStatic);
        attribute.setVisibility(visibility);
        attribute.setType(AstUtils.normalizeTypeName(fieldType, fragment.getExtraDimensions(), false));

        Expression expression = fragment.getInitializer();
        if (expression != null) {
            //attribute.setAssignment(srbForAttributes.buildSourceRepresentation(fileContent, expression.getStartPosition(), expression.getLength()));
            addClientCode(attribute.key().toString(), srbForAttributes.buildPartialSourceRepresentation(fileContent, expression));
        }
        attribute.setClientCode(srbForAttributes.buildEmptySourceRepresentation());
    }
    return true;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:25,代碼來源:BindingsRecoveryAstVisitor.java

示例2: rewriteAST

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final ASTRewrite rewrite = cuRewrite.getASTRewrite();
	VariableDeclarationFragment fragment = null;
	for (int i = 0; i < fNodes.length; i++) {
		final ASTNode node = fNodes[i];

		final AST ast = node.getAST();

		fragment = ast.newVariableDeclarationFragment();
		fragment.setName(ast.newSimpleName(NAME_FIELD));

		final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
		declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
		declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

		if (!addInitializer(fragment, node)) {
			continue;
		}

		if (fragment.getInitializer() != null) {

			final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
			if (node instanceof AbstractTypeDeclaration) {
				rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
			} else if (node instanceof AnonymousClassDeclaration) {
				rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
			} else if (node instanceof ParameterizedType) {
				final ParameterizedType type = (ParameterizedType) node;
				final ASTNode parent = type.getParent();
				if (parent instanceof ClassInstanceCreation) {
					final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
					final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
					if (anonymous != null) {
						rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
					}
				}
			} else {
				Assert.isTrue(false);
			}

			addLinkedPositions(rewrite, fragment, positionGroups);
		}

		final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
		if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
			final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	if (fragment == null) {
		return;
	}

	positionGroups.setEndPosition(rewrite.track(fragment));
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:57,代碼來源:AbstractSerialVersionOperation.java

示例3: visit

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration node) {

	int modifiers = node.getModifiers();
	if (Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) {
		List<VariableDeclarationFragment> fragments = node.fragments();
		for (VariableDeclarationFragment varDeclFrag : fragments) {
			IVariableBinding varBinding = varDeclFrag.resolveBinding();
			String enclosingClass = varBinding.getDeclaringClass().getQualifiedName();
			if(!varBinding.getType().isPrimitive() && !varBinding.getType().getQualifiedName().equals("java.lang.String")){
				final TACVariable fieldVar = new TACVariable(varBinding);
				if(!enclosingClass.equals(Config.MAINCLASS)){
					context.addEncapsulatedVariable(fieldVar);
				}
			}
		}
	}
	return super.visit(node);
}
 
開發者ID:aroog,項目名稱:code,代碼行數:20,代碼來源:HeuristicOwnedVisitor.java

示例4: ensureParameterFromSingleVariableDeclaration

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
public Parameter ensureParameterFromSingleVariableDeclaration(SingleVariableDeclaration variableDeclaration,
		Method method) {
	String name = variableDeclaration.getName().toString();
	String qualifiedName = Famix.qualifiedNameOf(method) + NAME_SEPARATOR + name;
	if (parameters.has(qualifiedName)) 
		return parameters.named(qualifiedName);
	Parameter parameter = new Parameter();
	parameters.add(qualifiedName, parameter);
	parameter.setName(name);
	parameter.setParentBehaviouralEntity(method);
	parameter.setDeclaredType(ensureTypeFromDomType(variableDeclaration.getType()));
	IVariableBinding binding = variableDeclaration.resolveBinding();
	if (binding != null) {
		createAnnotationInstancesToEntityFromAnnotationBinding(parameter, binding.getAnnotations());
		//We only recover the final modifier
		if (Modifier.isFinal(binding.getModifiers())) parameter.addModifiers("final");
	}
	return parameter;
}
 
開發者ID:feenkcom,項目名稱:jdt2famix,代碼行數:20,代碼來源:InJavaImporter.java

示例5: decideRuleKind

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
private static String decideRuleKind(ReferencedClassesParser parser, Set<String> dependencies) {
  CompilationUnit cu = parser.compilationUnit;
  if (cu.types().isEmpty()) {
    return "java_library";
  }
  AbstractTypeDeclaration topLevelClass = (AbstractTypeDeclaration) cu.types().get(0);
  if ((topLevelClass.getModifiers() & Modifier.ABSTRACT) != 0) {
    // Class is abstract, can't be a test.
    return "java_library";
  }

  // JUnit 4 tests
  if (parser.className.endsWith("Test") && dependencies.contains("org.junit.Test")) {
    return "java_test";
  }

  if (any(
      topLevelClass.bodyDeclarations(),
      d -> d instanceof MethodDeclaration && isMainMethod((MethodDeclaration) d))) {
    return "java_binary";
  }

  return "java_library";
}
 
開發者ID:bazelbuild,項目名稱:BUILD_file_generator,代碼行數:25,代碼來源:JavaSourceFileParser.java

示例6: visit

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration node) {
	List fragments = node.fragments();
	for(Object o : fragments) {
		VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
		String varName = frag.getName().getIdentifier();
		int line = cunit.getLineNumber(frag.getStartPosition());
		ASTNode parent = node.getParent();
		Scope scope = new Scope(cunit.getLineNumber(parent.getStartPosition()), getEndLine(parent, cunit));
		TypeDeclaration dec = (TypeDeclaration) node.getParent();
		String qName = dec.getName().getFullyQualifiedName();
		PackageDeclaration packageDec = cunit.getPackage();
		if(packageDec != null)
			qName = packageDec.getName().getFullyQualifiedName() + "." + qName;
		String type = !Modifier.isStatic(node.getModifiers()) ? qName : null; 
		VariableTags tags = new VariableTags(varName, type, line, scope, true);
		variables.add(tags);
	}
	return false;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:21,代碼來源:TagParser.java

示例7: visit

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
@Override
public boolean visit(TypeDeclaration node) {
	System.out.println(node.getParent().getClass());
	if(info == null)
		info = new ClassInfo(node.resolveBinding().getQualifiedName(), VisibilityInfo.from(node));
	
	
	for(FieldDeclaration f : node.getFields()) {
		if(!Modifier.isStatic(f.getModifiers())) {
			for(Object o : f.fragments()) {
				VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
				info.addField(new FieldInfo(frag.getName().toString()));
			}
		}

	}

	return true;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:20,代碼來源:Visitor.java

示例8: installLinkedVisibilityProposals

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
public static void installLinkedVisibilityProposals(LinkedProposalModel linkedProposalModel, ASTRewrite rewrite, List<IExtendedModifier> modifiers, boolean inInterface, String groupId) {
	ASTNode modifier = findVisibilityModifier(modifiers);
	if (modifier != null) {
		int selected = ((Modifier) modifier).getKeyword().toFlagValue();

		LinkedProposalPositionGroup positionGroup = linkedProposalModel.getPositionGroup(groupId, true);
		positionGroup.addPosition(rewrite.track(modifier), false);
		positionGroup.addProposal(new ModifierLinkedModeProposal(selected, 10));

		// add all others
		int[] flagValues = inInterface ? new int[] { Modifier.PUBLIC, 0 } : new int[] { Modifier.PUBLIC, 0, Modifier.PROTECTED, Modifier.PRIVATE };
		for (int i = 0; i < flagValues.length; i++) {
			if (flagValues[i] != selected) {
				positionGroup.addProposal(new ModifierLinkedModeProposal(flagValues[i], 9 - i));
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:19,代碼來源:ModifierCorrectionSubProcessor.java

示例9: getInterfaceMethodModifiers

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
private int getInterfaceMethodModifiers(ASTNode targetTypeDecl, boolean createAbstractMethod) {
	// for interface and annotation members copy the modifiers from an existing member
	if (targetTypeDecl instanceof TypeDeclaration) {
		TypeDeclaration type= (TypeDeclaration) targetTypeDecl;
		MethodDeclaration[] methodDecls= type.getMethods();
		if (methodDecls.length > 0) {
			if (createAbstractMethod) {
				for (MethodDeclaration methodDeclaration : methodDecls) {
					IMethodBinding methodBinding= methodDeclaration.resolveBinding();
					if (methodBinding != null && JdtFlags.isAbstract(methodBinding)) {
						return methodDeclaration.getModifiers();
					}
				}
			}
			return methodDecls[0].getModifiers() & Modifier.PUBLIC;
		}
		List<BodyDeclaration> bodyDecls= type.bodyDeclarations();
		if (bodyDecls.size() > 0) {
			return bodyDecls.get(0).getModifiers() & Modifier.PUBLIC;
		}
	}
	return 0;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:24,代碼來源:NewMethodCorrectionProposal.java

示例10: isMethodCompatible

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
public static boolean isMethodCompatible(IMethodBinding methodBinding) {

	Options options = Options.getInstance();
	if (!options.includeConstructors()
			&& (methodBinding.isConstructor() || methodBinding
					.isDefaultConstructor())) {
		return false;
	}
	if (!options.includeStaticMethods()
			&& Modifier.isStatic(methodBinding.getModifiers())) {
		return false;
	}

	return true;

}
 
開發者ID:aroog,項目名稱:code,代碼行數:17,代碼來源:Utils.java

示例11: makeParameterTypeVariable

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
public ParameterTypeVariable2 makeParameterTypeVariable(
    IMethodBinding methodBinding, int parameterIndex) {
  if (methodBinding == null) return null;
  TType type =
      getBoxedType(methodBinding.getParameterTypes()[parameterIndex], /*no boxing*/ null);
  if (type == null) return null;

  ParameterTypeVariable2 cv = new ParameterTypeVariable2(type, parameterIndex, methodBinding);
  ParameterTypeVariable2 storedCv = (ParameterTypeVariable2) storedCv(cv);
  if (storedCv == cv) {
    if (methodBinding.getDeclaringClass().isLocal()
        || Modifier.isPrivate(methodBinding.getModifiers())) fCuScopedConstraintVariables.add(cv);
    makeElementVariables(storedCv, type);
    makeArrayElementVariable(storedCv);
    if (fStoreToString)
      storedCv.setData(
          ConstraintVariable2.TO_STRING,
          "[Parameter("
              + parameterIndex
              + ","
              + Bindings.asString(methodBinding)
              + ")]"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  }
  return storedCv;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:26,代碼來源:InferTypeArgumentsTCModel.java

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

示例13: getBaseImageDescriptor

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
private static ImageDescriptor getBaseImageDescriptor(IBinding binding, int flags) {
  if (binding instanceof ITypeBinding) {
    ITypeBinding typeBinding = (ITypeBinding) binding;
    if (typeBinding.isArray()) {
      typeBinding = typeBinding.getElementType();
    }
    if (typeBinding.isCapture()) {
      typeBinding.getWildcard();
    }
    return getTypeImageDescriptor(typeBinding.getDeclaringClass() != null, typeBinding, flags);
  } else if (binding instanceof IMethodBinding) {
    ITypeBinding type = ((IMethodBinding) binding).getDeclaringClass();
    int modifiers = binding.getModifiers();
    if (type.isEnum()
        && (!Modifier.isPublic(modifiers)
            && !Modifier.isProtected(modifiers)
            && !Modifier.isPrivate(modifiers))
        && ((IMethodBinding) binding).isConstructor()) return JavaPluginImages.DESC_MISC_PRIVATE;
    return getMethodImageDescriptor(binding.getModifiers());
  } else if (binding instanceof IVariableBinding)
    return getFieldImageDescriptor((IVariableBinding) binding);
  return JavaPluginImages.DESC_OBJS_UNKNOWN;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:24,代碼來源:BindingLabelProvider.java

示例14: visit

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
@Override
public boolean visit(SimpleName node) {
  IBinding binding = node.resolveBinding();
  if (binding instanceof IVariableBinding) {
    int accessMode = fFormalArgument.getSimplifiedAccessMode();
    if (fFormalArgument.isFinal() && !Modifier.isFinal(binding.getModifiers())) {
      return setResult(false);
    }
    if (accessMode == FlowInfo.READ || accessMode == FlowInfo.UNUSED) return setResult(true);
    // from now on we only have write accesses.
    IVariableBinding vb = (IVariableBinding) binding;
    if (vb.isField()) return setResult(false);
    return setResult(
        fFlowInfo.hasAccessMode(fFlowContext, vb, FlowInfo.UNUSED | FlowInfo.WRITE));
  }
  return setResult(false);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:18,代碼來源:CallInliner.java

示例15: computeConstantDeclarationLocation

import org.eclipse.jdt.core.dom.Modifier; //導入依賴的package包/類
private void computeConstantDeclarationLocation() throws JavaModelException {
  if (isDeclarationLocationComputed()) return;

  BodyDeclaration lastStaticDependency = null;
  Iterator<BodyDeclaration> decls =
      getContainingTypeDeclarationNode().bodyDeclarations().iterator();

  while (decls.hasNext()) {
    BodyDeclaration decl = decls.next();

    int modifiers;
    if (decl instanceof FieldDeclaration) modifiers = ((FieldDeclaration) decl).getModifiers();
    else if (decl instanceof Initializer) modifiers = ((Initializer) decl).getModifiers();
    else {
      continue; /* this declaration is not a field declaration
                or initializer, so the placement of the constant
                declaration relative to it does not matter */
    }

    if (Modifier.isStatic(modifiers) && depends(getSelectedExpression(), decl))
      lastStaticDependency = decl;
  }

  if (lastStaticDependency == null) fInsertFirst = true;
  else fToInsertAfter = lastStaticDependency;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:27,代碼來源:ExtractConstantRefactoring.java


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