当前位置: 首页>>代码示例>>Java>>正文


Java Modifier.STATIC属性代码示例

本文整理汇总了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;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:24,代码来源:BindingsRecoveryAstVisitor.java

示例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());
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:36,代码来源:JavaSourceFileParser.java

示例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()]);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:75,代码来源:ExtractMethodRefactoring.java

示例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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:MissingReturnTypeCorrectionProposal.java

示例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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:38,代码来源:NewVariableCorrectionProposal.java

示例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()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:80,代码来源:ExtractMethodRefactoring.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:8,代码来源:SelfEncapsulateFieldRefactoring.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:MissingReturnTypeCorrectionProposal.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:38,代码来源:NewVariableCorrectionProposal.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:40,代码来源:NewMethodCorrectionProposal.java

示例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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:9,代码来源:SemanticHighlightings.java

示例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);
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:7,代码来源:UiBinderUtilities.java

示例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);
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:10,代码来源:UiBinderUtilities.java

示例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;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:52,代码来源:BindingsRecoveryAstVisitor.java

示例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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:49,代码来源:NewMethodCorrectionProposal.java


注:本文中的org.eclipse.jdt.core.dom.Modifier.STATIC属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。