Java 类org.eclipse.jdt.core.IPackageDeclaration 实例源码

项目:eclipse.jdt.ls    文件:CorrectPackageDeclarationProposal.java   
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
    super.addEdits(doc, root);

    ICompilationUnit cu= getCompilationUnit();

    IPackageFragment parentPack= (IPackageFragment) cu.getParent();
    IPackageDeclaration[] decls= cu.getPackageDeclarations();

    if (parentPack.isDefaultPackage() && decls.length > 0) {
        for (int i= 0; i < decls.length; i++) {
            ISourceRange range= decls[i].getSourceRange();
            root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
        }
        return;
    }
    if (!parentPack.isDefaultPackage() && decls.length == 0) {
        String lineDelim = "\n";
        String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
        root.addChild(new InsertEdit(0, str));
        return;
    }

    root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
项目:eclipse.jdt.ls    文件:CorrectPackageDeclarationProposal.java   
@Override
public String getName() {
    ICompilationUnit cu= getCompilationUnit();
    IPackageFragment parentPack= (IPackageFragment) cu.getParent();
    try {
        IPackageDeclaration[] decls= cu.getPackageDeclarations();
        if (parentPack.isDefaultPackage() && decls.length > 0) {
            return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
        }
        if (!parentPack.isDefaultPackage() && decls.length == 0) {
            return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description,  JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
        }
    } catch(JavaModelException e) {
        JavaLanguageServerPlugin.log(e);
    }
    return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
项目:eclipse.jdt.ls    文件:JDTUtilsTest.java   
@Test
public void testResolveStandaloneCompilationUnit() throws CoreException {
    Path helloSrcRoot = Paths.get("projects", "eclipse", "hello", "src").toAbsolutePath();
    URI uri = helloSrcRoot.resolve(Paths.get("java", "Foo.java")).toUri();
    ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri.toString());
    assertNotNull("Could not find compilation unit for " + uri, cu);
    assertEquals(ProjectsManager.DEFAULT_PROJECT_NAME, cu.getResource().getProject().getName());
    IJavaElement[] elements = cu.getChildren();
    assertEquals(2, elements.length);
    assertTrue(IPackageDeclaration.class.isAssignableFrom(elements[0].getClass()));
    assertTrue(IType.class.isAssignableFrom(elements[1].getClass()));
    assertTrue(cu.getResource().isLinked());
    assertEquals(cu.getResource(), JDTUtils.findResource(uri, ResourcesPlugin.getWorkspace().getRoot()::findFilesForLocationURI));

    uri = helloSrcRoot.resolve("NoPackage.java").toUri();
    cu = JDTUtils.resolveCompilationUnit(uri.toString());
    assertNotNull("Could not find compilation unit for " + uri, cu);
    assertEquals(ProjectsManager.DEFAULT_PROJECT_NAME, cu.getResource().getProject().getName());
    elements = cu.getChildren();
    assertEquals(1, elements.length);
    assertTrue(IType.class.isAssignableFrom(elements[0].getClass()));
}
项目:che    文件:ASTNodeSearchUtil.java   
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode)
    throws JavaModelException {
  switch (element.getElementType()) {
    case IJavaElement.FIELD:
      return new ASTNode[] {getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
    case IJavaElement.IMPORT_CONTAINER:
      return getImportNodes((IImportContainer) element, cuNode);
    case IJavaElement.IMPORT_DECLARATION:
      return new ASTNode[] {getImportDeclarationNode((IImportDeclaration) element, cuNode)};
    case IJavaElement.INITIALIZER:
      return new ASTNode[] {getInitializerNode((IInitializer) element, cuNode)};
    case IJavaElement.METHOD:
      return new ASTNode[] {
        getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)
      };
    case IJavaElement.PACKAGE_DECLARATION:
      return new ASTNode[] {getPackageDeclarationNode((IPackageDeclaration) element, cuNode)};
    case IJavaElement.TYPE:
      return new ASTNode[] {getAbstractTypeDeclarationNode((IType) element, cuNode)};
    default:
      Assert.isTrue(false, String.valueOf(element.getElementType()));
      return null;
  }
}
项目:che    文件:ProposalInfo.java   
/**
 * Extracts the Javadoc for the given Java element and returns it as HTML.
 *
 * @param element the Java element to get the documentation for
 * @return the Javadoc for Java element or <code>null</code> if the Javadoc is not available
 * @throws org.eclipse.core.runtime.CoreException if fetching the Javadoc for the given element
 *     failed connected
 */
private String extractJavadoc(IJavaElement element) throws CoreException {
  if (element instanceof IMember) {
    return JavadocContentAccess2.getHTMLContent(
        (IMember) element,
        true,
        UrlContextProvider.get(element.getJavaProject().getPath().toString()));
  } else if (element instanceof IPackageDeclaration) {
    return JavadocContentAccess2.getHTMLContent(
        (IPackageDeclaration) element,
        UrlContextProvider.get(element.getJavaProject().getPath().toString()));
  } else if (element instanceof IPackageFragment) {
    return JavadocContentAccess2.getHTMLContent(
        (IPackageFragment) element,
        UrlContextProvider.get(element.getJavaProject().getPath().toString()));
  }
  return null;
}
项目:che    文件:CorrectPackageDeclarationProposal.java   
@Override
public String getName() {
  ICompilationUnit cu = getCompilationUnit();
  IPackageFragment parentPack = (IPackageFragment) cu.getParent();
  try {
    IPackageDeclaration[] decls = cu.getPackageDeclarations();
    if (parentPack.isDefaultPackage() && decls.length > 0) {
      return Messages.format(
          CorrectionMessages.CorrectPackageDeclarationProposal_remove_description,
          BasicElementLabels.getJavaElementName(decls[0].getElementName()));
    }
    if (!parentPack.isDefaultPackage() && decls.length == 0) {
      return (Messages.format(
          CorrectionMessages.CorrectPackageDeclarationProposal_add_description,
          JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
    }
  } catch (JavaModelException e) {
    JavaPlugin.log(e);
  }
  return (Messages.format(
      CorrectionMessages.CorrectPackageDeclarationProposal_change_description,
      JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTNodeSearchUtil.java   
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode) throws JavaModelException {
    switch(element.getElementType()){
        case IJavaElement.FIELD:
            return new ASTNode[]{getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
        case IJavaElement.IMPORT_CONTAINER:
            return getImportNodes((IImportContainer)element, cuNode);
        case IJavaElement.IMPORT_DECLARATION:
            return new ASTNode[]{getImportDeclarationNode((IImportDeclaration)element, cuNode)};
        case IJavaElement.INITIALIZER:
            return new ASTNode[]{getInitializerNode((IInitializer)element, cuNode)};
        case IJavaElement.METHOD:
            return new ASTNode[]{getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)};
        case IJavaElement.PACKAGE_DECLARATION:
            return new ASTNode[]{getPackageDeclarationNode((IPackageDeclaration)element, cuNode)};
        case IJavaElement.TYPE:
            return new ASTNode[]{getAbstractTypeDeclarationNode((IType) element, cuNode)};
        default:
            Assert.isTrue(false, String.valueOf(element.getElementType()));
            return null;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RefactoringAvailabilityTester.java   
public static boolean isMoveAvailable(final IResource[] resources, final IJavaElement[] elements) throws JavaModelException {
    if (elements != null) {
        for (int index= 0; index < elements.length; index++) {
            IJavaElement element= elements[index];
            if (element == null || !element.exists())
                return false;
            if ((element instanceof IType) && ((IType) element).isLocal())
                return false;
            if ((element instanceof IPackageDeclaration))
                return false;
            if (element instanceof IField && JdtFlags.isEnum((IMember) element))
                return false;
        }
    }
    return ReorgPolicyFactory.createMovePolicy(resources, elements).canEnable();
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaEditorBreadcrumb.java   
/**
 * Returns the input for the given element. The Java breadcrumb does not show some elements of
 * the model:
 * <ul>
 *      <li><code>ITypeRoots</li>
 *      <li><code>IPackageDeclaration</li>
 *      <li><code>IImportContainer</li>
 *      <li><code>IImportDeclaration</li>
 * </ul>
 *
 * @param element the potential input element
 * @return the element to use as input
 */
private IJavaElement getInput(IJavaElement element) {
    try {
        if (element instanceof IImportDeclaration)
            element= element.getParent();

        if (element instanceof IImportContainer)
            element= element.getParent();

        if (element instanceof IPackageDeclaration)
            element= element.getParent();

        if (element instanceof ICompilationUnit) {
            IType[] types= ((ICompilationUnit) element).getTypes();
            if (types.length > 0)
                element= types[0];
        }

        if (element instanceof IClassFile)
            element= ((IClassFile) element).getType();

        return element;
    } catch (JavaModelException e) {
        return null;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CorrectPackageDeclarationProposal.java   
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
    super.addEdits(doc, root);

    ICompilationUnit cu= getCompilationUnit();

    IPackageFragment parentPack= (IPackageFragment) cu.getParent();
    IPackageDeclaration[] decls= cu.getPackageDeclarations();

    if (parentPack.isDefaultPackage() && decls.length > 0) {
        for (int i= 0; i < decls.length; i++) {
            ISourceRange range= decls[i].getSourceRange();
            root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
        }
        return;
    }
    if (!parentPack.isDefaultPackage() && decls.length == 0) {
        String lineDelim= StubUtility.getLineDelimiterUsed(cu);
        String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
        root.addChild(new InsertEdit(0, str));
        return;
    }

    root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
项目:Eclipse-Postfix-Code-Completion    文件:CorrectPackageDeclarationProposal.java   
@Override
public String getName() {
    ICompilationUnit cu= getCompilationUnit();
    IPackageFragment parentPack= (IPackageFragment) cu.getParent();
    try {
        IPackageDeclaration[] decls= cu.getPackageDeclarations();
        if (parentPack.isDefaultPackage() && decls.length > 0) {
            return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
        }
        if (!parentPack.isDefaultPackage() && decls.length == 0) {
            return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description,  JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
        }
    } catch(JavaModelException e) {
        JavaPlugin.log(e);
    }
    return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
项目:comment-tag-gen-plugin    文件:JavaSelectButton.java   
@Override
public void widgetSelected(SelectionEvent e) {
    Shell shell = Display.getDefault().getActiveShell();
    JavaSelectDialog dialog = new JavaSelectDialog(shell, "Please select a custom class.");
    dialog.open();
    ICompilationUnit unit = dialog.getCompilationUnit();
    String javaFileName = unit.getElementName();
    String javaName = javaFileName.replaceFirst(".java$", "");
    try {
        IPackageDeclaration declaration = unit.getPackageDeclarations()[0];
        String packageName = declaration.getElementName();
        String fullName = packageName + "." + javaName;
        text.setText(fullName);
    } catch (JavaModelException t) {
        throw Throwables.propagate(new SystemException(t));
    } finally {
        dialog.close();
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTNodeSearchUtil.java   
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode) throws JavaModelException {
    switch(element.getElementType()){
        case IJavaElement.FIELD:
            return new ASTNode[]{getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
        case IJavaElement.IMPORT_CONTAINER:
            return getImportNodes((IImportContainer)element, cuNode);
        case IJavaElement.IMPORT_DECLARATION:
            return new ASTNode[]{getImportDeclarationNode((IImportDeclaration)element, cuNode)};
        case IJavaElement.INITIALIZER:
            return new ASTNode[]{getInitializerNode((IInitializer)element, cuNode)};
        case IJavaElement.METHOD:
            return new ASTNode[]{getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)};
        case IJavaElement.PACKAGE_DECLARATION:
            return new ASTNode[]{getPackageDeclarationNode((IPackageDeclaration)element, cuNode)};
        case IJavaElement.TYPE:
            return new ASTNode[]{getAbstractTypeDeclarationNode((IType) element, cuNode)};
        default:
            Assert.isTrue(false, String.valueOf(element.getElementType()));
            return null;
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RefactoringAvailabilityTester.java   
public static boolean isMoveAvailable(final IResource[] resources, final IJavaElement[] elements) throws JavaModelException {
    if (elements != null) {
        for (int index= 0; index < elements.length; index++) {
            IJavaElement element= elements[index];
            if (element == null || !element.exists())
                return false;
            if ((element instanceof IType) && ((IType) element).isLocal())
                return false;
            if ((element instanceof IPackageDeclaration))
                return false;
            if (element instanceof IField && JdtFlags.isEnum((IMember) element))
                return false;
        }
    }
    return ReorgPolicyFactory.createMovePolicy(resources, elements).canEnable();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaEditorBreadcrumb.java   
/**
 * Returns the input for the given element. The Java breadcrumb does not show some elements of
 * the model:
 * <ul>
 *      <li><code>ITypeRoots</li>
 *      <li><code>IPackageDeclaration</li>
 *      <li><code>IImportContainer</li>
 *      <li><code>IImportDeclaration</li>
 * </ul>
 *
 * @param element the potential input element
 * @return the element to use as input
 */
private IJavaElement getInput(IJavaElement element) {
    try {
        if (element instanceof IImportDeclaration)
            element= element.getParent();

        if (element instanceof IImportContainer)
            element= element.getParent();

        if (element instanceof IPackageDeclaration)
            element= element.getParent();

        if (element instanceof ICompilationUnit) {
            IType[] types= ((ICompilationUnit) element).getTypes();
            if (types.length > 0)
                element= types[0];
        }

        if (element instanceof IClassFile)
            element= ((IClassFile) element).getType();

        return element;
    } catch (JavaModelException e) {
        return null;
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CorrectPackageDeclarationProposal.java   
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
    super.addEdits(doc, root);

    ICompilationUnit cu= getCompilationUnit();

    IPackageFragment parentPack= (IPackageFragment) cu.getParent();
    IPackageDeclaration[] decls= cu.getPackageDeclarations();

    if (parentPack.isDefaultPackage() && decls.length > 0) {
        for (int i= 0; i < decls.length; i++) {
            ISourceRange range= decls[i].getSourceRange();
            root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
        }
        return;
    }
    if (!parentPack.isDefaultPackage() && decls.length == 0) {
        String lineDelim= StubUtility.getLineDelimiterUsed(cu);
        String str= "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; //$NON-NLS-1$
        root.addChild(new InsertEdit(0, str));
        return;
    }

    root.addChild(new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CorrectPackageDeclarationProposal.java   
@Override
public String getName() {
    ICompilationUnit cu= getCompilationUnit();
    IPackageFragment parentPack= (IPackageFragment) cu.getParent();
    try {
        IPackageDeclaration[] decls= cu.getPackageDeclarations();
        if (parentPack.isDefaultPackage() && decls.length > 0) {
            return Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_remove_description, BasicElementLabels.getJavaElementName(decls[0].getElementName()));
        }
        if (!parentPack.isDefaultPackage() && decls.length == 0) {
            return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_add_description,  JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
        }
    } catch(JavaModelException e) {
        JavaPlugin.log(e);
    }
    return (Messages.format(CorrectionMessages.CorrectPackageDeclarationProposal_change_description, JavaElementLabels.getElementLabel(parentPack, JavaElementLabels.ALL_DEFAULT)));
}
项目:get-set-generator    文件:ProjectUtil.java   
public static String getImportDeclaration(IFile file, String className)
        throws JavaModelException {
    String fullyQualifiedName = null;
    ICompilationUnit currentFile = JavaCore.createCompilationUnitFrom(file);
    IImportDeclaration[] imports = currentFile.getImports();
    for (IImportDeclaration iImportDeclaration : imports) {
        if (iImportDeclaration.getElementName().endsWith(
                MethodUtil.PACKAGE_DOT + className)) {
            fullyQualifiedName = iImportDeclaration.getElementName();
            break;
        }
    }
    if (fullyQualifiedName == null || fullyQualifiedName.length() <= 0) {
        IPackageDeclaration packageDeclaration = currentFile
                .getPackageDeclarations()[0];
        fullyQualifiedName = packageDeclaration.getElementName()
                + MethodUtil.PACKAGE_DOT + className;
    }
    return fullyQualifiedName;
}
项目:seasar2-assistant    文件:NamingConventionUtil.java   
public static IPackageDeclaration getPackageDeclaration(ICompilationUnit cu) {
    try {
        IPackageDeclaration[] pds = cu.getPackageDeclarations();
        int i = 0, j = -1, count = 0;
        for (; i < pds.length; i++) {
            if (pds[i].exists()) {
                count++;
                j = i;
            }
        }
        if (count != 1) {
            return null;
        }
        return pds[j];
    } catch (JavaModelException e) {
        LoggerUtil.error(e);
        return null;
    }
}
项目:reflectify    文件:AbstractJavaModelTests.java   
protected ICompilationUnit getCompilationUnitFor(IJavaElement element) {

        if (element instanceof ICompilationUnit) {
            return (ICompilationUnit)element;
        }

        if (element instanceof IMember) {
            return ((IMember)element).getCompilationUnit();
        }

        if (element instanceof IPackageDeclaration ||
            element instanceof IImportDeclaration) {
                return (ICompilationUnit)element.getParent();
            }

        return null;

    }
项目:che    文件:RefactoringAvailabilityTester.java   
public static boolean isMoveAvailable(final IResource[] resources, final IJavaElement[] elements)
    throws JavaModelException {
  if (elements != null) {
    for (int index = 0; index < elements.length; index++) {
      IJavaElement element = elements[index];
      if (element == null || !element.exists()) return false;
      if ((element instanceof IType) && ((IType) element).isLocal()) return false;
      if ((element instanceof IPackageDeclaration)) return false;
      if (element instanceof IField && JdtFlags.isEnum((IMember) element)) return false;
    }
  }
  return ReorgPolicyFactory.createMovePolicy(resources, elements).canEnable();
}
项目:che    文件:ReorgPolicyFactory.java   
private void copyPackageDeclarationToDestination(
    IPackageDeclaration declaration,
    ASTRewrite targetRewrite,
    CompilationUnit sourceCuNode,
    CompilationUnit destinationCuNode)
    throws JavaModelException {
  if (destinationCuNode.getPackage() != null) return;
  PackageDeclaration sourceNode =
      ASTNodeSearchUtil.getPackageDeclarationNode(declaration, sourceCuNode);
  PackageDeclaration copiedNode =
      (PackageDeclaration) ASTNode.copySubtree(targetRewrite.getAST(), sourceNode);
  targetRewrite.set(destinationCuNode, CompilationUnit.PACKAGE_PROPERTY, copiedNode, null);
}
项目:che    文件:CorrectPackageDeclarationProposal.java   
@Override
protected void addEdits(IDocument doc, TextEdit root) throws CoreException {
  super.addEdits(doc, root);

  ICompilationUnit cu = getCompilationUnit();

  IPackageFragment parentPack = (IPackageFragment) cu.getParent();
  IPackageDeclaration[] decls = cu.getPackageDeclarations();

  if (parentPack.isDefaultPackage() && decls.length > 0) {
    for (int i = 0; i < decls.length; i++) {
      ISourceRange range = decls[i].getSourceRange();
      root.addChild(new DeleteEdit(range.getOffset(), range.getLength()));
    }
    return;
  }
  if (!parentPack.isDefaultPackage() && decls.length == 0) {
    String lineDelim = StubUtility.getLineDelimiterUsed(cu);
    String str =
        "package " + parentPack.getElementName() + ';' + lineDelim + lineDelim; // $NON-NLS-1$
    root.addChild(new InsertEdit(0, str));
    return;
  }

  root.addChild(
      new ReplaceEdit(fLocation.getOffset(), fLocation.getLength(), parentPack.getElementName()));
}
项目:txtUML    文件:WizardUtils.java   
public static List<IPackageFragment> getModelPackages(List<IPackageFragment> packageFragments) {
    List<IPackageFragment> modelPackages = new ArrayList<>();
    for (IPackageFragment pFragment : packageFragments) {
        Optional<ICompilationUnit> foundPackageInfoCompilationUnit = Optional
                .of(pFragment.getCompilationUnit(PackageUtils.PACKAGE_INFO));

        if (!foundPackageInfoCompilationUnit.isPresent() || !foundPackageInfoCompilationUnit.get().exists()) {
            continue;
        }

        ICompilationUnit packageInfoCompilationUnit = foundPackageInfoCompilationUnit.get();

        try {
            for (IPackageDeclaration packDecl : packageInfoCompilationUnit.getPackageDeclarations()) {
                for (IAnnotation annot : packDecl.getAnnotations()) {
                    boolean isModelPackage = isImportedNameResolvedTo(packageInfoCompilationUnit,
                            annot.getElementName(), Model.class.getCanonicalName());

                    if (isModelPackage) {
                        modelPackages.add(pFragment);
                        break;
                    }
                }
            }
        } catch (JavaModelException ex) {
            return Collections.emptyList();
        }
    }
    return modelPackages;
}
项目:txtUML    文件:ElementTypeTeller.java   
private static boolean checkPackageInfo(ICompilationUnit compUnit) throws JavaModelException {
    for (IPackageDeclaration packDecl : compUnit.getPackageDeclarations()) {
        for (IAnnotation annot : packDecl.getAnnotations()) {
            // Because names are not resolved in IJavaElement AST
            // representation, we have to manually check if a given
            // annotation is really the Model annotation.
            if (isImportedNameResolvedTo(compUnit, annot.getElementName(), Model.class.getCanonicalName())) {
                return true;
            }
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:ReorgPolicyFactory.java   
private void copyPackageDeclarationToDestination(IPackageDeclaration declaration, ASTRewrite targetRewrite, CompilationUnit sourceCuNode, CompilationUnit destinationCuNode) throws JavaModelException {
    if (destinationCuNode.getPackage() != null)
        return;
    PackageDeclaration sourceNode= ASTNodeSearchUtil.getPackageDeclarationNode(declaration, sourceCuNode);
    PackageDeclaration copiedNode= (PackageDeclaration) ASTNode.copySubtree(targetRewrite.getAST(), sourceNode);
    targetRewrite.set(destinationCuNode, CompilationUnit.PACKAGE_PROPERTY, copiedNode, null);
}
项目:Eclipse-Postfix-Code-Completion    文件:ReorgPolicyFactory.java   
protected void copyToDestination(IJavaElement element, CompilationUnitRewrite targetRewriter, CompilationUnit sourceCuNode, CompilationUnit targetCuNode) throws CoreException {
    final ASTRewrite rewrite= targetRewriter.getASTRewrite();
    switch (element.getElementType()) {
        case IJavaElement.FIELD:
            copyMemberToDestination((IMember) element, targetRewriter, sourceCuNode, targetCuNode, createNewFieldDeclarationNode(((IField) element), rewrite, sourceCuNode));
            break;
        case IJavaElement.IMPORT_CONTAINER:
            copyImportsToDestination((IImportContainer) element, rewrite, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.IMPORT_DECLARATION:
            copyImportToDestination((IImportDeclaration) element, rewrite, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.INITIALIZER:
            copyInitializerToDestination((IInitializer) element, targetRewriter, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.METHOD:
            copyMethodToDestination((IMethod) element, targetRewriter, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.PACKAGE_DECLARATION:
            copyPackageDeclarationToDestination((IPackageDeclaration) element, rewrite, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.TYPE:
            copyTypeToDestination((IType) element, targetRewriter, sourceCuNode, targetCuNode);
            break;

        default:
            Assert.isTrue(false);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CopyQualifiedNameAction.java   
private boolean isValidElement(Object element) {
    if (element instanceof IMember)
        return true;

    if (element instanceof IClassFile)
        return true;

    if (element instanceof ICompilationUnit)
        return true;

    if (element instanceof IPackageDeclaration)
        return true;

    if (element instanceof IImportDeclaration)
        return true;

    if (element instanceof IPackageFragment)
        return true;

    if (element instanceof IPackageFragmentRoot)
        return true;

    if (element instanceof IJavaProject)
        return true;

    if (element instanceof IJarEntryResource)
        return true;

    if (element instanceof IResource)
        return true;

    if (element instanceof LogicalPackage)
        return true;

    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:ProposalInfo.java   
/**
 * Extracts the Javadoc for the given Java element and returns it as HTML.
 * 
 * @param element the Java element to get the documentation for
 * @return the Javadoc for Java element or <code>null</code> if the Javadoc is not available
 * @throws CoreException if fetching the Javadoc for the given element failed connected
 */
private String extractJavadoc(IJavaElement element) throws CoreException {
    if (element instanceof IMember) {
        return JavadocContentAccess2.getHTMLContent((IMember) element, true);
    } else if (element instanceof IPackageDeclaration) {
        return JavadocContentAccess2.getHTMLContent((IPackageDeclaration) element);
    } else if (element instanceof IPackageFragment) {
        return JavadocContentAccess2.getHTMLContent((IPackageFragment) element);
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:ReorgCorrectionsSubProcessor.java   
public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
    ICompilationUnit cu= context.getCompilationUnit();
    boolean isLinked= cu.getResource().isLinked();

    // correct package declaration
    int relevance= cu.getPackageDeclarations().length == 0 ? IProposalRelevance.MISSING_PACKAGE_DECLARATION : IProposalRelevance.CORRECT_PACKAGE_DECLARATION; // bug 38357
    proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance));

    // move to package
    IPackageDeclaration[] packDecls= cu.getPackageDeclarations();
    String newPackName= packDecls.length > 0 ? packDecls[0].getElementName() : ""; //$NON-NLS-1$

    IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(cu);
    IPackageFragment newPack= root.getPackageFragment(newPackName);

    ICompilationUnit newCU= newPack.getCompilationUnit(cu.getElementName());
    if (!newCU.exists() && !isLinked) {
        String label;
        if (newPack.isDefaultPackage()) {
            label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu));
        } else {
            String packageLabel= JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT);
            label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel });
        }
        CompositeChange composite= new CompositeChange(label);
        composite.add(new CreatePackageChange(newPack));
        composite.add(new MoveCompilationUnitChange(cu, newPack));

        proposals.add(new ChangeCorrectionProposal(label, composite, IProposalRelevance.MOVE_CU_TO_PACKAGE, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE)));
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaElementLinks.java   
public JavaElementLinkedLabelComposer(IJavaElement member, StringBuffer buf) {
    super(buf);
    if (member instanceof IPackageDeclaration) {
        fElement= member.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
    } else {
        fElement= member;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaElementLinks.java   
@Override
public String getElementName(IJavaElement element) {
    if (element instanceof IPackageFragment || element instanceof IPackageDeclaration) {
        return getPackageFragmentElementName(element);
    }

    String elementName= element.getElementName();
    return getElementName(element, elementName);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaBrowsingContentProvider.java   
private Object[] removeImportAndPackageDeclarations(Object[] members) {
    ArrayList<Object> tempResult= new ArrayList<Object>(members.length);
    for (int i= 0; i < members.length; i++)
        if (!(members[i] instanceof IImportContainer) && !(members[i] instanceof IPackageDeclaration))
            tempResult.add(members[i]);
    return tempResult.toArray();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ReorgPolicyFactory.java   
private void copyPackageDeclarationToDestination(IPackageDeclaration declaration, ASTRewrite targetRewrite, CompilationUnit sourceCuNode, CompilationUnit destinationCuNode) throws JavaModelException {
    if (destinationCuNode.getPackage() != null)
        return;
    PackageDeclaration sourceNode= ASTNodeSearchUtil.getPackageDeclarationNode(declaration, sourceCuNode);
    PackageDeclaration copiedNode= (PackageDeclaration) ASTNode.copySubtree(targetRewrite.getAST(), sourceNode);
    targetRewrite.set(destinationCuNode, CompilationUnit.PACKAGE_PROPERTY, copiedNode, null);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ReorgPolicyFactory.java   
protected void copyToDestination(IJavaElement element, CompilationUnitRewrite targetRewriter, CompilationUnit sourceCuNode, CompilationUnit targetCuNode) throws CoreException {
    final ASTRewrite rewrite= targetRewriter.getASTRewrite();
    switch (element.getElementType()) {
        case IJavaElement.FIELD:
            copyMemberToDestination((IMember) element, targetRewriter, sourceCuNode, targetCuNode, createNewFieldDeclarationNode(((IField) element), rewrite, sourceCuNode));
            break;
        case IJavaElement.IMPORT_CONTAINER:
            copyImportsToDestination((IImportContainer) element, rewrite, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.IMPORT_DECLARATION:
            copyImportToDestination((IImportDeclaration) element, rewrite, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.INITIALIZER:
            copyInitializerToDestination((IInitializer) element, targetRewriter, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.METHOD:
            copyMethodToDestination((IMethod) element, targetRewriter, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.PACKAGE_DECLARATION:
            copyPackageDeclarationToDestination((IPackageDeclaration) element, rewrite, sourceCuNode, targetCuNode);
            break;
        case IJavaElement.TYPE:
            copyTypeToDestination((IType) element, targetRewriter, sourceCuNode, targetCuNode);
            break;

        default:
            Assert.isTrue(false);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CopyQualifiedNameAction.java   
private boolean isValidElement(Object element) {
    if (element instanceof IMember)
        return true;

    if (element instanceof IClassFile)
        return true;

    if (element instanceof ICompilationUnit)
        return true;

    if (element instanceof IPackageDeclaration)
        return true;

    if (element instanceof IImportDeclaration)
        return true;

    if (element instanceof IPackageFragment)
        return true;

    if (element instanceof IPackageFragmentRoot)
        return true;

    if (element instanceof IJavaProject)
        return true;

    if (element instanceof IJarEntryResource)
        return true;

    if (element instanceof IResource)
        return true;

    if (element instanceof LogicalPackage)
        return true;

    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ReorgCorrectionsSubProcessor.java   
public static void getWrongPackageDeclNameProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
    ICompilationUnit cu= context.getCompilationUnit();
    boolean isLinked= cu.getResource().isLinked();

    // correct package declaration
    int relevance= cu.getPackageDeclarations().length == 0 ? 7 : 5; // bug 38357
    proposals.add(new CorrectPackageDeclarationProposal(cu, problem, relevance));

    // move to package
    IPackageDeclaration[] packDecls= cu.getPackageDeclarations();
    String newPackName= packDecls.length > 0 ? packDecls[0].getElementName() : ""; //$NON-NLS-1$

    IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(cu);
    IPackageFragment newPack= root.getPackageFragment(newPackName);

    ICompilationUnit newCU= newPack.getCompilationUnit(cu.getElementName());
    if (!newCU.exists() && !isLinked) {
        String label;
        if (newPack.isDefaultPackage()) {
            label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_default_description, BasicElementLabels.getFileName(cu));
        } else {
            String packageLabel= JavaElementLabels.getElementLabel(newPack, JavaElementLabels.ALL_DEFAULT);
            label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_movecu_description, new Object[] { BasicElementLabels.getFileName(cu), packageLabel });
        }
        CompositeChange composite= new CompositeChange(label);
        composite.add(new CreatePackageChange(newPack));
        composite.add(new MoveCompilationUnitChange(cu, newPack));

        proposals.add(new ChangeCorrectionProposal(label, composite, 6, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_MOVE)));
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaBrowsingContentProvider.java   
private Object[] removeImportAndPackageDeclarations(Object[] members) {
    ArrayList<Object> tempResult= new ArrayList<Object>(members.length);
    for (int i= 0; i < members.length; i++)
        if (!(members[i] instanceof IImportContainer) && !(members[i] instanceof IPackageDeclaration))
            tempResult.add(members[i]);
    return tempResult.toArray();
}
项目:NTNU-Master-Project    文件:WorkspaceManager.java   
private Listener.ProblemMarkersFile getProblemMarkers(ICompilationUnit compilationUnit) throws CoreException {
    IPackageDeclaration[] packageDeclarations = compilationUnit.getPackageDeclarations();
    String packageName = packageDeclarations[0].getElementName();
    String fileName = compilationUnit.getElementName();

    IResource javaSourceFile = compilationUnit.getUnderlyingResource();
    IMarker[] markers = javaSourceFile.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);

    return new Listener.ProblemMarkersFile(packageName, fileName, markers);
}
项目:masteroppgave    文件:WorkspaceManager.java   
private Listener.ProblemMarkersFile getProblemMarkers(ICompilationUnit compilationUnit) throws CoreException {
    IPackageDeclaration[] packageDeclarations = compilationUnit.getPackageDeclarations();
    String packageName = packageDeclarations[0].getElementName();
    String fileName = compilationUnit.getElementName();

    IResource javaSourceFile = compilationUnit.getUnderlyingResource();
    IMarker[] markers = javaSourceFile.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);

    return new Listener.ProblemMarkersFile(packageName, fileName, markers);
}