本文整理汇总了Java中org.eclipse.jdt.core.dom.Modifier.STATIC属性的典型用法代码示例。如果您正苦于以下问题:Java Modifier.STATIC属性的具体用法?Java Modifier.STATIC怎么用?Java Modifier.STATIC使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.eclipse.jdt.core.dom.Modifier
的用法示例。
在下文中一共展示了Modifier.STATIC属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
@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: isMainMethod
/**
* Returns true iff 'methodDeclaration' represents a void static method named 'main' that takes a
* single String[] parameter.
*/
private static boolean isMainMethod(MethodDeclaration methodDeclaration) {
// Is it static?
if ((methodDeclaration.getModifiers() & Modifier.STATIC) == 0) {
return false;
}
// Does it return void?
Type returnType = methodDeclaration.getReturnType2();
if (!returnType.isPrimitiveType()) {
return false;
}
if (((PrimitiveType) returnType).getPrimitiveTypeCode() != PrimitiveType.VOID) {
return false;
}
// Is it called 'main'?
if (!"main".equals(methodDeclaration.getName().getIdentifier())) {
return false;
}
// Does it have a single parameter?
if (methodDeclaration.parameters().size() != 1) {
return false;
}
// Is the parameter's type String[]?
SingleVariableDeclaration pt =
getOnlyElement((List<SingleVariableDeclaration>) methodDeclaration.parameters());
IVariableBinding vb = pt.resolveBinding();
if (vb == null) {
return false;
}
ITypeBinding tb = vb.getType();
return tb != null && "java.lang.String[]".equals(tb.getQualifiedName());
}
示例3: createCallNodes
private ASTNode[] createCallNodes(SnippetFinder.Match duplicate, int modifiers) {
List<ASTNode> result = new ArrayList<>(2);
IVariableBinding[] locals = fAnalyzer.getCallerLocals();
for (int i = 0; i < locals.length; i++) {
result.add(createDeclaration(locals[i], null));
}
MethodInvocation invocation = fAST.newMethodInvocation();
invocation.setName(fAST.newSimpleName(fMethodName));
ASTNode typeNode = ASTResolving.findParentType(fAnalyzer.getEnclosingBodyDeclaration());
RefactoringStatus status = new RefactoringStatus();
while (fDestination != typeNode) {
fAnalyzer.checkInput(status, fMethodName, typeNode);
if (!status.isOK()) {
SimpleName destinationTypeName = fAST.newSimpleName(ASTNodes.getEnclosingType(fDestination).getName());
if ((modifiers & Modifier.STATIC) == 0) {
ThisExpression thisExpression = fAST.newThisExpression();
thisExpression.setQualifier(destinationTypeName);
invocation.setExpression(thisExpression);
} else {
invocation.setExpression(destinationTypeName);
}
break;
}
typeNode = typeNode.getParent();
}
List<Expression> arguments = invocation.arguments();
for (int i = 0; i < fParameterInfos.size(); i++) {
ParameterInfo parameter = fParameterInfos.get(i);
arguments.add(ASTNodeFactory.newName(fAST, getMappedName(duplicate, parameter)));
}
if (fLinkedProposalModel != null) {
LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
nameGroup.addPosition(fRewriter.track(invocation.getName()), false);
}
ASTNode call;
int returnKind = fAnalyzer.getReturnKind();
switch (returnKind) {
case ExtractMethodAnalyzer.ACCESS_TO_LOCAL:
IVariableBinding binding = fAnalyzer.getReturnLocal();
if (binding != null) {
VariableDeclarationStatement decl = createDeclaration(getMappedBinding(duplicate, binding), invocation);
call = decl;
} else {
Assignment assignment = fAST.newAssignment();
assignment.setLeftHandSide(ASTNodeFactory.newName(fAST, getMappedBinding(duplicate, fAnalyzer.getReturnValue()).getName()));
assignment.setRightHandSide(invocation);
call = assignment;
}
break;
case ExtractMethodAnalyzer.RETURN_STATEMENT_VALUE:
ReturnStatement rs = fAST.newReturnStatement();
rs.setExpression(invocation);
call = rs;
break;
default:
call = invocation;
}
if (call instanceof Expression && !fAnalyzer.isExpressionSelected()) {
call = fAST.newExpressionStatement((Expression) call);
}
result.add(call);
// We have a void return statement. The code looks like
// extracted();
// return;
if (returnKind == ExtractMethodAnalyzer.RETURN_STATEMENT_VOID && !fAnalyzer.isLastStatementSelected()) {
result.add(fAST.newReturnStatement());
}
return result.toArray(new ASTNode[result.size()]);
}
示例4: testModifier
protected boolean testModifier(IVariableBinding curr) {
int modifiers= curr.getModifiers();
int staticFinal= Modifier.STATIC | Modifier.FINAL;
if ((modifiers & staticFinal) == staticFinal) {
return false;
}
if (Modifier.isStatic(modifiers) && !Modifier.isStatic(getModifiers())) {
return false;
}
return true;
}
示例5: evaluateFieldModifiers
private int evaluateFieldModifiers(ASTNode newTypeDecl) {
if (fSenderBinding.isAnnotation()) {
return 0;
}
if (fSenderBinding.isInterface()) {
// for interface members copy the modifiers from an existing field
FieldDeclaration[] fieldDecls= ((TypeDeclaration) newTypeDecl).getFields();
if (fieldDecls.length > 0) {
return fieldDecls[0].getModifiers();
}
return 0;
}
int modifiers= 0;
if (fVariableKind == CONST_FIELD) {
modifiers |= Modifier.FINAL | Modifier.STATIC;
} else {
ASTNode parent= fOriginalNode.getParent();
if (parent instanceof QualifiedName) {
IBinding qualifierBinding= ((QualifiedName)parent).getQualifier().resolveBinding();
if (qualifierBinding instanceof ITypeBinding) {
modifiers |= Modifier.STATIC;
}
} else if (ASTResolving.isInStaticContext(fOriginalNode)) {
modifiers |= Modifier.STATIC;
}
}
ASTNode node= ASTResolving.findParentType(fOriginalNode, true);
if (newTypeDecl.equals(node)) {
modifiers |= Modifier.PRIVATE;
} else if (node instanceof AnonymousClassDeclaration) {
modifiers |= Modifier.PROTECTED;
} else {
modifiers |= Modifier.PUBLIC;
}
return modifiers;
}
示例6: createCallNodes
private ASTNode[] createCallNodes(SnippetFinder.Match duplicate, int modifiers) {
List<ASTNode> result = new ArrayList<ASTNode>(2);
IVariableBinding[] locals = fAnalyzer.getCallerLocals();
for (int i = 0; i < locals.length; i++) {
result.add(createDeclaration(locals[i], null));
}
MethodInvocation invocation = fAST.newMethodInvocation();
invocation.setName(fAST.newSimpleName(fMethodName));
ASTNode typeNode = ASTResolving.findParentType(fAnalyzer.getEnclosingBodyDeclaration());
RefactoringStatus status = new RefactoringStatus();
while (fDestination != typeNode) {
fAnalyzer.checkInput(status, fMethodName, typeNode);
if (!status.isOK()) {
SimpleName destinationTypeName =
fAST.newSimpleName(ASTNodes.getEnclosingType(fDestination).getName());
if ((modifiers & Modifier.STATIC) == 0) {
ThisExpression thisExpression = fAST.newThisExpression();
thisExpression.setQualifier(destinationTypeName);
invocation.setExpression(thisExpression);
} else {
invocation.setExpression(destinationTypeName);
}
break;
}
typeNode = typeNode.getParent();
}
List<Expression> arguments = invocation.arguments();
for (int i = 0; i < fParameterInfos.size(); i++) {
ParameterInfo parameter = fParameterInfos.get(i);
arguments.add(ASTNodeFactory.newName(fAST, getMappedName(duplicate, parameter)));
}
if (fLinkedProposalModel != null) {
LinkedProposalPositionGroup nameGroup = fLinkedProposalModel.getPositionGroup(KEY_NAME, true);
nameGroup.addPosition(fRewriter.track(invocation.getName()), false);
}
ASTNode call;
int returnKind = fAnalyzer.getReturnKind();
switch (returnKind) {
case ExtractMethodAnalyzer.ACCESS_TO_LOCAL:
IVariableBinding binding = fAnalyzer.getReturnLocal();
if (binding != null) {
VariableDeclarationStatement decl =
createDeclaration(getMappedBinding(duplicate, binding), invocation);
call = decl;
} else {
Assignment assignment = fAST.newAssignment();
assignment.setLeftHandSide(
ASTNodeFactory.newName(
fAST, getMappedBinding(duplicate, fAnalyzer.getReturnValue()).getName()));
assignment.setRightHandSide(invocation);
call = assignment;
}
break;
case ExtractMethodAnalyzer.RETURN_STATEMENT_VALUE:
ReturnStatement rs = fAST.newReturnStatement();
rs.setExpression(invocation);
call = rs;
break;
default:
call = invocation;
}
if (call instanceof Expression && !fAnalyzer.isExpressionSelected()) {
call = fAST.newExpressionStatement((Expression) call);
}
result.add(call);
// We have a void return statement. The code looks like
// extracted();
// return;
if (returnKind == ExtractMethodAnalyzer.RETURN_STATEMENT_VOID
&& !fAnalyzer.isLastStatementSelected()) {
result.add(fAST.newReturnStatement());
}
return result.toArray(new ASTNode[result.size()]);
}
示例7: createModifiers
private int createModifiers() throws JavaModelException {
int result = 0;
if (Flags.isPublic(fVisibility)) result |= Modifier.PUBLIC;
else if (Flags.isProtected(fVisibility)) result |= Modifier.PROTECTED;
else if (Flags.isPrivate(fVisibility)) result |= Modifier.PRIVATE;
if (JdtFlags.isStatic(fField)) result |= Modifier.STATIC;
return result;
}
示例8: testModifier
protected boolean testModifier(IVariableBinding curr) {
int modifiers = curr.getModifiers();
int staticFinal = Modifier.STATIC | Modifier.FINAL;
if ((modifiers & staticFinal) == staticFinal) {
return false;
}
if (Modifier.isStatic(modifiers) && !Modifier.isStatic(getModifiers())) {
return false;
}
return true;
}
示例9: evaluateFieldModifiers
private int evaluateFieldModifiers(ASTNode newTypeDecl) {
if (fSenderBinding.isAnnotation()) {
return 0;
}
if (fSenderBinding.isInterface()) {
// for interface members copy the modifiers from an existing field
FieldDeclaration[] fieldDecls = ((TypeDeclaration) newTypeDecl).getFields();
if (fieldDecls.length > 0) {
return fieldDecls[0].getModifiers();
}
return 0;
}
int modifiers = 0;
if (fVariableKind == CONST_FIELD) {
modifiers |= Modifier.FINAL | Modifier.STATIC;
} else {
ASTNode parent = fOriginalNode.getParent();
if (parent instanceof QualifiedName) {
IBinding qualifierBinding = ((QualifiedName) parent).getQualifier().resolveBinding();
if (qualifierBinding instanceof ITypeBinding) {
modifiers |= Modifier.STATIC;
}
} else if (ASTResolving.isInStaticContext(fOriginalNode)) {
modifiers |= Modifier.STATIC;
}
}
ASTNode node = ASTResolving.findParentType(fOriginalNode, true);
if (newTypeDecl.equals(node)) {
modifiers |= Modifier.PRIVATE;
} else if (node instanceof AnonymousClassDeclaration) {
modifiers |= Modifier.PROTECTED;
} else {
modifiers |= Modifier.PUBLIC;
}
return modifiers;
}
示例10: evaluateModifiers
private int evaluateModifiers(ASTNode targetTypeDecl) {
if (getSenderBinding().isAnnotation()) {
return 0;
}
if (getSenderBinding().isInterface()) {
// for interface and annotation members copy the modifiers from an existing field
MethodDeclaration[] methodDecls = ((TypeDeclaration) targetTypeDecl).getMethods();
if (methodDecls.length > 0) {
return methodDecls[0].getModifiers();
}
return 0;
}
ASTNode invocationNode = getInvocationNode();
if (invocationNode instanceof MethodInvocation) {
int modifiers = 0;
Expression expression = ((MethodInvocation) invocationNode).getExpression();
if (expression != null) {
if (expression instanceof Name
&& ((Name) expression).resolveBinding().getKind() == IBinding.TYPE) {
modifiers |= Modifier.STATIC;
}
} else if (ASTResolving.isInStaticContext(invocationNode)) {
modifiers |= Modifier.STATIC;
}
ASTNode node = ASTResolving.findParentType(invocationNode);
if (targetTypeDecl.equals(node)) {
modifiers |= Modifier.PRIVATE;
} else if (node instanceof AnonymousClassDeclaration
&& ASTNodes.isParent(node, targetTypeDecl)) {
modifiers |= Modifier.PROTECTED;
if (ASTResolving.isInStaticContext(node) && expression == null) {
modifiers |= Modifier.STATIC;
}
} else {
modifiers |= Modifier.PUBLIC;
}
return modifiers;
}
return Modifier.PUBLIC;
}
示例11: consumes
@Override
public boolean consumes(SemanticToken token) {
IBinding binding = token.getBinding();
return binding != null
&& binding.getKind() == IBinding.VARIABLE
&& ((IVariableBinding) binding).isField()
&& (binding.getModifiers() & (Modifier.FINAL | Modifier.STATIC))
== (Modifier.FINAL | Modifier.STATIC);
}
示例12: isUiField
public static boolean isUiField(FieldDeclaration fieldDecl) {
if ((fieldDecl.getModifiers() & Modifier.STATIC) != 0) {
return false;
}
return (JavaASTUtils.findAnnotation(fieldDecl,
UiBinderConstants.UI_FIELD_ANNOTATION_NAME) != null);
}
示例13: isUiHandler
public static boolean isUiHandler(MethodDeclaration method) {
if ((method.getModifiers() & Modifier.STATIC) != 0) {
return false;
}
if (method.isConstructor()) {
return false;
}
return (JavaASTUtils.findAnnotation(method,
UiBinderConstants.UI_HANDLER_TYPE_NAME) != null);
}
示例14: visit
public boolean visit(MethodDeclaration methodDeclaration) {
// ASTNode parentNode = methodDeclaration.getParent();
// if (!(parentNode instanceof TypeDeclaration)) {
// // ignore methods from anonymous classes
// return false;
// }
String methodSignature = AstUtils.getSignatureFromMethodDeclaration(methodDeclaration);
// if
// (methodDeclaration.getName().getIdentifier().equals("execMultiLineCommands"))
// {
// System.out.println("x");
//
// }
final RastNode method = model.createMethod(methodSignature, containerStack.peek(), sourceFilePath, methodDeclaration.isConstructor(), methodDeclaration);
List<?> modifiers = methodDeclaration.modifiers();
Set<String> annotations = extractAnnotationTypes(modifiers);
boolean deprecated = annotations.contains("Deprecated") || AstUtils.containsDeprecatedTag(methodDeclaration.getJavadoc());
if (deprecated) {
method.addStereotypes(Stereotype.DEPRECATED);
}
int methodModifiers = methodDeclaration.getModifiers();
Visibility visibility = getVisibility(methodModifiers);
boolean isStatic = (methodModifiers & Modifier.STATIC) != 0;
if (!isStatic) {
method.addStereotypes(Stereotype.TYPE_MEMBER);
}
//method.setVisibility(visibility);
extractParametersAndReturnType(model, methodDeclaration, method);
Block body = methodDeclaration.getBody();
if (body == null) {
method.addStereotypes(Stereotype.ABSTRACT);
} else {
final List<String> references = new ArrayList<String>();
body.accept(new DependenciesAstVisitor(true) {
@Override
protected void onMethodAccess(ASTNode node, IMethodBinding binding) {
String methodKey = AstUtils.getKeyFromMethodBinding(binding);
references.add(methodKey);
}
});
postProcessReferences.put(method, references);
}
return true;
}
示例15: evaluateModifiers
private int evaluateModifiers(ASTNode targetTypeDecl) {
if (getSenderBinding().isAnnotation()) {
return 0;
}
boolean isTargetInterface= getSenderBinding().isInterface();
if (isTargetInterface && !JavaModelUtil.is18OrHigher(getCompilationUnit().getJavaProject())) {
// only abstract methods are allowed for interface present in less than Java 1.8
return getInterfaceMethodModifiers(targetTypeDecl, true);
}
ASTNode invocationNode= getInvocationNode();
if (invocationNode instanceof MethodInvocation) {
int modifiers= 0;
Expression expression= ((MethodInvocation)invocationNode).getExpression();
if (expression != null) {
if (expression instanceof Name && ((Name) expression).resolveBinding().getKind() == IBinding.TYPE) {
modifiers |= Modifier.STATIC;
}
} else if (ASTResolving.isInStaticContext(invocationNode)) {
modifiers |= Modifier.STATIC;
}
ASTNode node= ASTResolving.findParentType(invocationNode);
boolean isParentInterface= node instanceof TypeDeclaration && ((TypeDeclaration) node).isInterface();
if (isTargetInterface || isParentInterface) {
if (expression == null && !targetTypeDecl.equals(node)) {
modifiers|= Modifier.STATIC;
if (isTargetInterface) {
modifiers|= getInterfaceMethodModifiers(targetTypeDecl, false);
} else {
modifiers|= Modifier.PROTECTED;
}
} else if (modifiers == Modifier.STATIC) {
modifiers= getInterfaceMethodModifiers(targetTypeDecl, false) | Modifier.STATIC;
} else {
modifiers= getInterfaceMethodModifiers(targetTypeDecl, true);
}
} else if (targetTypeDecl.equals(node)) {
modifiers |= Modifier.PRIVATE;
} else if (node instanceof AnonymousClassDeclaration && ASTNodes.isParent(node, targetTypeDecl)) {
modifiers |= Modifier.PROTECTED;
if (ASTResolving.isInStaticContext(node) && expression == null) {
modifiers |= Modifier.STATIC;
}
} else {
modifiers |= Modifier.PUBLIC;
}
return modifiers;
}
return Modifier.PUBLIC;
}