本文整理汇总了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;
}
示例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));
}
示例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);
}
示例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;
}
示例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";
}
示例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;
}
示例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;
}
示例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));
}
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}