Java 类com.intellij.psi.SyntheticElement 实例源码

项目:intellij-ce-playground    文件:GrPackageInspection.java   
@Nullable
private static PsiElement getElementToHighlight(GroovyFile file) {
  GrPackageDefinition packageDefinition = file.getPackageDefinition();
  if (packageDefinition != null) return packageDefinition;

  PsiClass[] classes = file.getClasses();
  for (PsiClass aClass : classes) {
    if (!(aClass instanceof SyntheticElement) && aClass instanceof GrTypeDefinition) {
      return ((GrTypeDefinition)aClass).getNameIdentifierGroovy();
    }
  }

  GrTopStatement[] statements = file.getTopStatements();
  if (statements.length > 0) {
    GrTopStatement first = statements[0];
    if (first instanceof GrNamedElement) return ((GrNamedElement)first).getNameIdentifierGroovy();

    return first;
  }

  return null;
}
项目:tools-idea    文件:GrPackageInspection.java   
@Nullable
private static PsiElement getElementToHighlight(GroovyFile file) {
  GrPackageDefinition packageDefinition = file.getPackageDefinition();
  if (packageDefinition != null) return packageDefinition;

  PsiClass[] classes = file.getClasses();
  for (PsiClass aClass : classes) {
    if (!(aClass instanceof SyntheticElement) && aClass instanceof GrTypeDefinition) {
      return ((GrTypeDefinition)aClass).getNameIdentifierGroovy();
    }
  }

  GrTopStatement[] statements = file.getTopStatements();
  if (statements.length > 0) {
    GrTopStatement first = statements[0];
    if (first instanceof GrNamedElement) return ((GrNamedElement)first).getNameIdentifierGroovy();

    return first;
  }

  return null;
}
项目:consulo-csharp    文件:IntroduceLocalVariableIntention.java   
@Override
@RequiredDispatchThread
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement psi)
{
    CSharpExpressionStatementImpl exprStmt = PsiTreeUtil.getParentOfType(psi, CSharpExpressionStatementImpl.class);
    if(psi instanceof SyntheticElement || exprStmt == null)
    {
        return false;
    }

    DotNetExpression expression = exprStmt.getExpression();
    if(expression instanceof CSharpAssignmentExpressionImpl)
    {
        return false;
    }

    DotNetTypeRef ref = expression.toTypeRef(true);
    return !(ref == DotNetTypeRef.ERROR_TYPE || DotNetTypeRefUtil.isVmQNameEqual(ref, expression, DotNetTypes.System.Void));
}
项目:intellij-ce-playground    文件:RenameElementAction.java   
@Override
public boolean isEnabledOnElements(@NotNull PsiElement[] elements) {
  if (elements.length != 1) return false;

  PsiElement element = elements[0];
  return element instanceof PsiNamedElement &&
         !(element instanceof SyntheticElement) && 
         !PsiElementRenameHandler.isVetoed(element);
}
项目:tools-idea    文件:RenameElementAction.java   
@Override
public boolean isEnabledOnElements(@NotNull PsiElement[] elements) {
  if (elements.length != 1) return false;

  PsiElement element = elements[0];
  return element instanceof PsiNamedElement && !(element instanceof SyntheticElement);
}
项目:consulo    文件:RenameElementAction.java   
@Override
public boolean isEnabledOnElements(@Nonnull PsiElement[] elements) {
  if (elements.length != 1) return false;

  PsiElement element = elements[0];
  return element instanceof PsiNamedElement && !(element instanceof SyntheticElement);
}
项目:consulo-java    文件:BaseGenerateAction.java   
@Nullable
protected PsiClass getTargetClass(Editor editor, PsiFile file)
{
    int offset = editor.getCaretModel().getOffset();
    PsiElement element = file.findElementAt(offset);
    if(element == null)
    {
        return null;
    }
    final PsiClass target = PsiTreeUtil.getParentOfType(element, PsiClass.class);
    return target instanceof SyntheticElement ? null : target;
}
项目:consulo-java    文件:SourcePosition.java   
@Nullable
protected PsiElement calcPsiElement() {
  PsiFile psiFile = getFile();
  int lineNumber = getLine();
  if(lineNumber < 0) {
    return psiFile;
  }

  final Document document = PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
  if (document == null) {
    return null;
  }
  if (lineNumber >= document.getLineCount()) {
    return psiFile;
  }
  int startOffset = document.getLineStartOffset(lineNumber);
  if(startOffset == -1) {
    return null;
  }

  PsiElement rootElement = psiFile;

  List<PsiFile> allFiles = psiFile.getViewProvider().getAllFiles();
  if (allFiles.size() > 1) { // jsp & gsp
    PsiClassOwner owner = ContainerUtil.findInstance(allFiles, PsiClassOwner.class);
    if (owner != null) {
      PsiClass[] classes = owner.getClasses();
      if (classes.length == 1 && classes[0]  instanceof SyntheticElement) {
        rootElement = classes[0];
      }
    }
  }

  PsiElement element;
  while(true) {
    final CharSequence charsSequence = document.getCharsSequence();
    for (; startOffset < charsSequence.length(); startOffset++) {
      char c = charsSequence.charAt(startOffset);
      if (c != ' ' && c != '\t') {
        break;
      }
    }
    element = rootElement.findElementAt(startOffset);

    if(element instanceof PsiComment) {
      startOffset = element.getTextRange().getEndOffset() + 1;
    }
    else{
      break;
    }
  }

  if (element != null && element.getParent() instanceof PsiForStatement) {
    return ((PsiForStatement)element.getParent()).getInitialization();
  }
  return element;
}